Skip to content

Commit bf0fa07

Browse files
authored
feat: add pathfinding exercise (#2537)
1 parent c30d44e commit bf0fa07

File tree

4 files changed

+305
-0
lines changed

4 files changed

+305
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
{
2+
"exercise": "relative-distance",
3+
"cases": [
4+
{
5+
"uuid": "4a1ded74-5d32-47fb-8ae5-321f51d06b5b",
6+
"description": "Direct parent-child relation",
7+
"property": "degreeOfSeparation",
8+
"input": {
9+
"familyTree": {
10+
"Vera": ["Tomoko"],
11+
"Tomoko": ["Aditi"]
12+
},
13+
"personA": "Vera",
14+
"personB": "Tomoko"
15+
},
16+
"expected": 1
17+
},
18+
{
19+
"uuid": "30d17269-83e9-4f82-a0d7-8ef9656d8dce",
20+
"description": "Sibling relationship",
21+
"property": "degreeOfSeparation",
22+
"input": {
23+
"familyTree": {
24+
"Dalia": ["Olga", "Yassin"]
25+
},
26+
"personA": "Olga",
27+
"personB": "Yassin"
28+
},
29+
"expected": 1
30+
},
31+
{
32+
"uuid": "8dffa27d-a8ab-496d-80b3-2f21c77648b5",
33+
"description": "Two degrees of separation, grandchild",
34+
"property": "degreeOfSeparation",
35+
"input": {
36+
"familyTree": {
37+
"Khadija": ["Mateo"],
38+
"Mateo": ["Rami"]
39+
},
40+
"personA": "Khadija",
41+
"personB": "Rami"
42+
},
43+
"expected": 2
44+
},
45+
{
46+
"uuid": "34e56ec1-d528-4a42-908e-020a4606ee60",
47+
"description": "Unrelated individuals",
48+
"comments": [
49+
"Some languages may return 0, -1 or similar to indicate no relation"
50+
],
51+
"property": "degreeOfSeparation",
52+
"input": {
53+
"familyTree": {
54+
"Priya": ["Rami"],
55+
"Kaito": ["Elif"]
56+
},
57+
"personA": "Priya",
58+
"personB": "Kaito"
59+
},
60+
"expected": null
61+
},
62+
{
63+
"uuid": "93ffe989-bad2-48c4-878f-3acb1ce2611b",
64+
"description": "Complex graph, cousins",
65+
"property": "degreeOfSeparation",
66+
"input": {
67+
"familyTree": {
68+
"Aiko": ["Bao", "Carlos"],
69+
"Bao": ["Dalia", "Elias"],
70+
"Carlos": ["Fatima", "Gustavo"],
71+
"Dalia": ["Hassan", "Isla"],
72+
"Elias": ["Javier"],
73+
"Fatima": ["Khadija", "Liam"],
74+
"Gustavo": ["Mina"],
75+
"Hassan": ["Noah", "Olga"],
76+
"Isla": ["Pedro"],
77+
"Javier": ["Quynh", "Ravi"],
78+
"Khadija": ["Sofia"],
79+
"Liam": ["Tariq", "Uma"],
80+
"Mina": ["Viktor", "Wang"],
81+
"Noah": ["Xiomara"],
82+
"Olga": ["Yuki"],
83+
"Pedro": ["Zane", "Aditi"],
84+
"Quynh": ["Boris"],
85+
"Ravi": ["Celine"],
86+
"Sofia": ["Diego", "Elif"],
87+
"Tariq": ["Farah"],
88+
"Uma": ["Giorgio"],
89+
"Viktor": ["Hana", "Ian"],
90+
"Wang": ["Jing"],
91+
"Xiomara": ["Kaito"],
92+
"Yuki": ["Leila"],
93+
"Zane": ["Mateo"],
94+
"Aditi": ["Nia"],
95+
"Boris": ["Oscar"],
96+
"Celine": ["Priya"],
97+
"Diego": ["Qi"],
98+
"Elif": ["Rami"],
99+
"Farah": ["Sven"],
100+
"Giorgio": ["Tomoko"],
101+
"Hana": ["Umar"],
102+
"Ian": ["Vera"],
103+
"Jing": ["Wyatt"],
104+
"Kaito": ["Xia"],
105+
"Leila": ["Yassin"],
106+
"Mateo": ["Zara"],
107+
"Nia": ["Antonio"],
108+
"Oscar": ["Bianca"],
109+
"Priya": ["Cai"],
110+
"Qi": ["Dimitri"],
111+
"Rami": ["Ewa"],
112+
"Sven": ["Fabio"],
113+
"Tomoko": ["Gabriela"],
114+
"Umar": ["Helena"],
115+
"Vera": ["Igor"],
116+
"Wyatt": ["Jun"],
117+
"Xia": ["Kim"],
118+
"Yassin": ["Lucia"],
119+
"Zara": ["Mohammed"]
120+
},
121+
"personA": "Dimitri",
122+
"personB": "Fabio"
123+
},
124+
"expected": 4
125+
},
126+
{
127+
"uuid": "2cc2e76b-013a-433c-9486-1dbe29bf06e5",
128+
"description": "Complex graph, no shortcut, far removed nephew",
129+
"property": "degreeOfSeparation",
130+
"input": {
131+
"familyTree": {
132+
"Aiko": ["Bao", "Carlos"],
133+
"Bao": ["Dalia", "Elias"],
134+
"Carlos": ["Fatima", "Gustavo"],
135+
"Dalia": ["Hassan", "Isla"],
136+
"Elias": ["Javier"],
137+
"Fatima": ["Khadija", "Liam"],
138+
"Gustavo": ["Mina"],
139+
"Hassan": ["Noah", "Olga"],
140+
"Isla": ["Pedro"],
141+
"Javier": ["Quynh", "Ravi"],
142+
"Khadija": ["Sofia"],
143+
"Liam": ["Tariq", "Uma"],
144+
"Mina": ["Viktor", "Wang"],
145+
"Noah": ["Xiomara"],
146+
"Olga": ["Yuki"],
147+
"Pedro": ["Zane", "Aditi"],
148+
"Quynh": ["Boris"],
149+
"Ravi": ["Celine"],
150+
"Sofia": ["Diego", "Elif"],
151+
"Tariq": ["Farah"],
152+
"Uma": ["Giorgio"],
153+
"Viktor": ["Hana", "Ian"],
154+
"Wang": ["Jing"],
155+
"Xiomara": ["Kaito"],
156+
"Yuki": ["Leila"],
157+
"Zane": ["Mateo"],
158+
"Aditi": ["Nia"],
159+
"Boris": ["Oscar"],
160+
"Celine": ["Priya"],
161+
"Diego": ["Qi"],
162+
"Elif": ["Rami"],
163+
"Farah": ["Sven"],
164+
"Giorgio": ["Tomoko"],
165+
"Hana": ["Umar"],
166+
"Ian": ["Vera"],
167+
"Jing": ["Wyatt"],
168+
"Kaito": ["Xia"],
169+
"Leila": ["Yassin"],
170+
"Mateo": ["Zara"],
171+
"Nia": ["Antonio"],
172+
"Oscar": ["Bianca"],
173+
"Priya": ["Cai"],
174+
"Qi": ["Dimitri"],
175+
"Rami": ["Ewa"],
176+
"Sven": ["Fabio"],
177+
"Tomoko": ["Gabriela"],
178+
"Umar": ["Helena"],
179+
"Vera": ["Igor"],
180+
"Wyatt": ["Jun"],
181+
"Xia": ["Kim"],
182+
"Yassin": ["Lucia"],
183+
"Zara": ["Mohammed"]
184+
},
185+
"personA": "Lucia",
186+
"personB": "Jun"
187+
},
188+
"expected": 15
189+
},
190+
{
191+
"uuid": "46c9fbcb-e464-455f-a718-049ea3c7400a",
192+
"description": "Complex graph, some shortcuts, cross-down and cross-up, cousins three times removed",
193+
"property": "degreeOfSeparation",
194+
"input": {
195+
"familyTree": {
196+
"Aiko": ["Bao", "Carlos"],
197+
"Bao": ["Dalia", "Elias"],
198+
"Carlos": ["Fatima", "Gustavo"],
199+
"Dalia": ["Hassan", "Isla"],
200+
"Elias": ["Javier"],
201+
"Fatima": ["Khadija", "Liam"],
202+
"Gustavo": ["Mina"],
203+
"Hassan": ["Noah", "Olga"],
204+
"Isla": ["Pedro"],
205+
"Javier": ["Quynh", "Ravi"],
206+
"Khadija": ["Viktor"],
207+
"Liam": ["Tariq", "Uma"],
208+
"Mina": ["Viktor", "Wang"],
209+
"Noah": ["Xiomara"],
210+
"Olga": ["Yuki"],
211+
"Pedro": ["Zane", "Aditi"],
212+
"Quynh": ["Boris"],
213+
"Ravi": ["Celine"],
214+
"Sofia": ["Diego", "Elif"],
215+
"Tariq": ["Farah"],
216+
"Uma": ["Giorgio"],
217+
"Viktor": ["Hana", "Ian"],
218+
"Wang": ["Jing"],
219+
"Xiomara": ["Kaito"],
220+
"Yuki": ["Leila"],
221+
"Zane": ["Mateo"],
222+
"Aditi": ["Nia"],
223+
"Boris": ["Oscar"],
224+
"Celine": ["Priya"],
225+
"Diego": ["Qi"],
226+
"Elif": ["Rami"],
227+
"Farah": ["Sven"],
228+
"Giorgio": ["Tomoko"],
229+
"Hana": ["Umar"],
230+
"Ian": ["Vera"],
231+
"Jing": ["Wyatt"],
232+
"Kaito": ["Xia"],
233+
"Leila": ["Yassin"],
234+
"Mateo": ["Zara"],
235+
"Nia": ["Antonio"],
236+
"Oscar": ["Bianca"],
237+
"Priya": ["Cai"],
238+
"Qi": ["Dimitri"],
239+
"Rami": ["Ewa"],
240+
"Sven": ["Fabio"],
241+
"Tomoko": ["Gabriela"],
242+
"Umar": ["Helena"],
243+
"Vera": ["Igor"],
244+
"Wyatt": ["Jun"],
245+
"Xia": ["Kim"],
246+
"Yassin": ["Lucia"],
247+
"Zara": ["Mohammed"]
248+
},
249+
"personA": "Tomoko",
250+
"personB": "Qi"
251+
},
252+
"expected": 8
253+
}
254+
]
255+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Instructions
2+
3+
Your task is to determine the degree of separation between two individuals in a family tree.
4+
5+
- You will be given an input, with all parent names and their children.
6+
- Each name is unique, a child _can_ have one or two parents.
7+
- The degree of separation is defined as the shortest number of connections from one person to another.
8+
- If two individuals are not connected, return a value that represents "no known relationship."
9+
Please see the test cases for the actual implementation.
10+
11+
## Example
12+
13+
Given the following family tree:
14+
15+
```text
16+
┌──────────┐ ┌──────────┐ ┌───────────┐
17+
│ Helena │ │ Erdős │ │ Shusaku │
18+
└───┬───┬──┘ └─────┬────┘ └──────┬────┘
19+
┌───┘ └───────┐ └──────┬──────┘
20+
▼ ▼ ▼
21+
┌──────────┐ ┌────────┐ ┌──────────┐
22+
│ Isla │ │ Tariq │ │ Kevin │
23+
└────┬─────┘ └────┬───┘ └──────────┘
24+
▼ ▼
25+
┌─────────┐ ┌────────┐
26+
│ Uma │ │ Morphy │
27+
└─────────┘ └────────┘
28+
```
29+
30+
The degree of separation between Tariq and Uma is 3 (Tariq → Helena → Isla → Uma).
31+
There's no known relationship between Isla and [Kevin][six-bacons], as there is no connection in the given data.
32+
The degree of separation between Uma and Isla is 1.
33+
34+
[six-bacons]: https://en.m.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Introduction
2+
3+
You've been hired to develop **Noble Knots**, the hottest new dating app for nobility!
4+
With centuries of royal intermarriage, things have gotten… _complicated_.
5+
To avoid any _oops-we're-twins_ situations, your job is to build a system that checks how closely two people are related.
6+
7+
Noble Knots is inspired by Iceland's "[Islendinga-App][islendiga-app]," which is backed up by a database that traces all known family connections between Icelanders from the time of the settlement of Iceland.
8+
Your algorithm will determine the **degree of separation** between two individuals in the royal family tree.
9+
10+
Will your app help crown a perfect match?
11+
12+
[islendiga-app]: http://www.islendingaapp.is/information-in-english/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title = "Relative Distance"
2+
blurb = "Given a family tree, calculate the degree of separation."
3+
source = "vaeng"
4+
source_url = "https://github.com/exercism/problem-specifications/pull/2537"

0 commit comments

Comments
 (0)