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," 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?
Your task is to determine the degree of separation between two individuals in a family tree.
Given the following family tree:
ββββββββββββ ββββββββββββ βββββββββββββ
β 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, as there is no connection in the given data. The degree of separation between Uma and Isla is 1.
Isla and Tariq are siblings and have a separation of 1. Similarly, this implementation would report a separation of 2 from you to your father's brother.
Sign up to Exercism to learn and master PowerShell with 128 exercises, and real human mentoring, all for free.