Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pathfinding exercise #2537

Merged
merged 12 commits into from
Mar 3, 2025
255 changes: 255 additions & 0 deletions exercises/relative-distance/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
{
"exercise": "relative-distance",
"cases": [
{
"uuid": "4a1ded74-5d32-47fb-8ae5-321f51d06b5b",
"description": "Direct parent-child relation",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Vera": ["Tomoko"],
"Tomoko": ["Aditi"]
},
"personA": "Vera",
"personB": "Tomoko"
},
"expected": 1
},
{
"uuid": "30d17269-83e9-4f82-a0d7-8ef9656d8dce",
"description": "Sibling relationship",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Dalia": ["Olga", "Yassin"]
},
"personA": "Olga",
"personB": "Yassin"
},
"expected": 1
},
{
"uuid": "8dffa27d-a8ab-496d-80b3-2f21c77648b5",
"description": "Two degrees of separation, grandchild",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Khadija": ["Mateo"],
"Mateo": ["Rami"]
},
"personA": "Khadija",
"personB": "Rami"
},
"expected": 2
},
{
"uuid": "34e56ec1-d528-4a42-908e-020a4606ee60",
"description": "Unrelated individuals",
"comments": [
"Some languages may return 0, -1 or similar to indicate no relation"
],
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Priya": ["Rami"],
"Kaito": ["Elif"]
},
"personA": "Priya",
"personB": "Kaito"
},
"expected": null
},
{
"uuid": "93ffe989-bad2-48c4-878f-3acb1ce2611b",
"description": "Complex graph, cousins",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Aiko": ["Bao", "Carlos"],
"Bao": ["Dalia", "Elias"],
"Carlos": ["Fatima", "Gustavo"],
"Dalia": ["Hassan", "Isla"],
"Elias": ["Javier"],
"Fatima": ["Khadija", "Liam"],
"Gustavo": ["Mina"],
"Hassan": ["Noah", "Olga"],
"Isla": ["Pedro"],
"Javier": ["Quynh", "Ravi"],
"Khadija": ["Sofia"],
"Liam": ["Tariq", "Uma"],
"Mina": ["Viktor", "Wang"],
"Noah": ["Xiomara"],
"Olga": ["Yuki"],
"Pedro": ["Zane", "Aditi"],
"Quynh": ["Boris"],
"Ravi": ["Celine"],
"Sofia": ["Diego", "Elif"],
"Tariq": ["Farah"],
"Uma": ["Giorgio"],
"Viktor": ["Hana", "Ian"],
"Wang": ["Jing"],
"Xiomara": ["Kaito"],
"Yuki": ["Leila"],
"Zane": ["Mateo"],
"Aditi": ["Nia"],
"Boris": ["Oscar"],
"Celine": ["Priya"],
"Diego": ["Qi"],
"Elif": ["Rami"],
"Farah": ["Sven"],
"Giorgio": ["Tomoko"],
"Hana": ["Umar"],
"Ian": ["Vera"],
"Jing": ["Wyatt"],
"Kaito": ["Xia"],
"Leila": ["Yassin"],
"Mateo": ["Zara"],
"Nia": ["Antonio"],
"Oscar": ["Bianca"],
"Priya": ["Cai"],
"Qi": ["Dimitri"],
"Rami": ["Ewa"],
"Sven": ["Fabio"],
"Tomoko": ["Gabriela"],
"Umar": ["Helena"],
"Vera": ["Igor"],
"Wyatt": ["Jun"],
"Xia": ["Kim"],
"Yassin": ["Lucia"],
"Zara": ["Mohammed"]
},
"personA": "Dimitri",
"personB": "Fabio"
},
"expected": 4
},
{
"uuid": "2cc2e76b-013a-433c-9486-1dbe29bf06e5",
"description": "Complex graph, no shortcut, far removed nephew",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Aiko": ["Bao", "Carlos"],
"Bao": ["Dalia", "Elias"],
"Carlos": ["Fatima", "Gustavo"],
"Dalia": ["Hassan", "Isla"],
"Elias": ["Javier"],
"Fatima": ["Khadija", "Liam"],
"Gustavo": ["Mina"],
"Hassan": ["Noah", "Olga"],
"Isla": ["Pedro"],
"Javier": ["Quynh", "Ravi"],
"Khadija": ["Sofia"],
"Liam": ["Tariq", "Uma"],
"Mina": ["Viktor", "Wang"],
"Noah": ["Xiomara"],
"Olga": ["Yuki"],
"Pedro": ["Zane", "Aditi"],
"Quynh": ["Boris"],
"Ravi": ["Celine"],
"Sofia": ["Diego", "Elif"],
"Tariq": ["Farah"],
"Uma": ["Giorgio"],
"Viktor": ["Hana", "Ian"],
"Wang": ["Jing"],
"Xiomara": ["Kaito"],
"Yuki": ["Leila"],
"Zane": ["Mateo"],
"Aditi": ["Nia"],
"Boris": ["Oscar"],
"Celine": ["Priya"],
"Diego": ["Qi"],
"Elif": ["Rami"],
"Farah": ["Sven"],
"Giorgio": ["Tomoko"],
"Hana": ["Umar"],
"Ian": ["Vera"],
"Jing": ["Wyatt"],
"Kaito": ["Xia"],
"Leila": ["Yassin"],
"Mateo": ["Zara"],
"Nia": ["Antonio"],
"Oscar": ["Bianca"],
"Priya": ["Cai"],
"Qi": ["Dimitri"],
"Rami": ["Ewa"],
"Sven": ["Fabio"],
"Tomoko": ["Gabriela"],
"Umar": ["Helena"],
"Vera": ["Igor"],
"Wyatt": ["Jun"],
"Xia": ["Kim"],
"Yassin": ["Lucia"],
"Zara": ["Mohammed"]
},
"personA": "Lucia",
"personB": "Jun"
},
"expected": 15
},
{
"uuid": "46c9fbcb-e464-455f-a718-049ea3c7400a",
"description": "Complex graph, some shortcuts, cross-down and cross-up, cousins three times removed",
"property": "degreeOfSeparation",
"input": {
"familyTree": {
"Aiko": ["Bao", "Carlos"],
"Bao": ["Dalia", "Elias"],
"Carlos": ["Fatima", "Gustavo"],
"Dalia": ["Hassan", "Isla"],
"Elias": ["Javier"],
"Fatima": ["Khadija", "Liam"],
"Gustavo": ["Mina"],
"Hassan": ["Noah", "Olga"],
"Isla": ["Pedro"],
"Javier": ["Quynh", "Ravi"],
"Khadija": ["Viktor"],
"Liam": ["Tariq", "Uma"],
"Mina": ["Viktor", "Wang"],
"Noah": ["Xiomara"],
"Olga": ["Yuki"],
"Pedro": ["Zane", "Aditi"],
"Quynh": ["Boris"],
"Ravi": ["Celine"],
"Sofia": ["Diego", "Elif"],
"Tariq": ["Farah"],
"Uma": ["Giorgio"],
"Viktor": ["Hana", "Ian"],
"Wang": ["Jing"],
"Xiomara": ["Kaito"],
"Yuki": ["Leila"],
"Zane": ["Mateo"],
"Aditi": ["Nia"],
"Boris": ["Oscar"],
"Celine": ["Priya"],
"Diego": ["Qi"],
"Elif": ["Rami"],
"Farah": ["Sven"],
"Giorgio": ["Tomoko"],
"Hana": ["Umar"],
"Ian": ["Vera"],
"Jing": ["Wyatt"],
"Kaito": ["Xia"],
"Leila": ["Yassin"],
"Mateo": ["Zara"],
"Nia": ["Antonio"],
"Oscar": ["Bianca"],
"Priya": ["Cai"],
"Qi": ["Dimitri"],
"Rami": ["Ewa"],
"Sven": ["Fabio"],
"Tomoko": ["Gabriela"],
"Umar": ["Helena"],
"Vera": ["Igor"],
"Wyatt": ["Jun"],
"Xia": ["Kim"],
"Yassin": ["Lucia"],
"Zara": ["Mohammed"]
},
"personA": "Tomoko",
"personB": "Qi"
},
"expected": 8
}
]
}
34 changes: 34 additions & 0 deletions exercises/relative-distance/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Instructions

Your task is to determine the degree of separation between two individuals in a family tree.

- You will be given an input, with all parent names and their children.
- Each name is unique, a child _can_ have one or two parents.
- The degree of separation is defined as the shortest number of connections from one person to another.
- If two individuals are not connected, return a value that represents "no known relationship."
Please see the test cases for the actual implementation.

## Example

Given the following family tree:

```text
┌──────────┐ ┌──────────┐ ┌───────────┐
│ Helena │ │ Erdős │ │ Shusaku │
└───┬───┬──┘ └─────┬────┘ └──────┬────┘
┌───┘ └───────┐ └──────┬──────┘
▼ ▼ ▼
┌──────────┐ ┌────────┐ ┌──────────┐
│ Isla │ │ Tariq │ │ Kevin │
└────┬─────┘ └────┬───┘ └──────────┘
▼ ▼
┌─────────┐ ┌────────┐
│ Uma │ │ Morphy │
└─────────┘ └────────┘
```

The degree of separation between Tariq and Uma is 3 (Tariq → Helena → Isla → Uma).
There's no known relationship between Isla and [Kevin][six-bacons], as there is no connection in the given data.
The degree of separation between Uma and Isla is 1.

[six-bacons]: https://en.m.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon
12 changes: 12 additions & 0 deletions exercises/relative-distance/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Introduction

You've been hired to develop **Noble Knots**, the hottest new dating app for nobility!
With centuries of royal intermarriage, things have gotten… _complicated_.
To avoid any _oops-we're-twins_ situations, your job is to build a system that checks how closely two people are related.

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.
Your algorithm will determine the **degree of separation** between two individuals in the royal family tree.

Will your app help crown a perfect match?

[islendiga-app]: http://www.islendingaapp.is/information-in-english/
4 changes: 4 additions & 0 deletions exercises/relative-distance/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = "Relative Distance"
blurb = "Given a family tree, calculate the degree of separation."
source = "vaeng"
source_url = "https://github.com/exercism/problem-specifications/pull/2537"
Loading