diff --git a/config.json b/config.json index f5c6e4e70..5b34f73f0 100644 --- a/config.json +++ b/config.json @@ -2731,6 +2731,22 @@ ], "difficulty": 6 }, + { + "slug": "relative-distance", + "name": "Relative Distance", + "uuid": "4f4229ce-5a2a-415c-a682-6a56cf3846ac", + "practices": [ + "constructors", + "dictionaries" + ], + "prerequisites": [ + "arrays", + "classes", + "constructors", + "dictionaries" + ], + "difficulty": 5 + }, { "slug": "split-second-stopwatch", "name": "Split-Second Stopwatch", diff --git a/exercises/Exercises.sln b/exercises/Exercises.sln index 75af82cce..178a42268 100644 --- a/exercises/Exercises.sln +++ b/exercises/Exercises.sln @@ -367,6 +367,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "swift-scheduling", "swift-s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftScheduling", "practice\swift-scheduling\SwiftScheduling.csproj", "{9A073412-4B64-48EB-A346-A56DE6847CCC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RelativeDistance", "practice\relative-distance\RelativeDistance.csproj", "{2C37454E-8624-47B8-A09B-ADE201C2B04C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -2525,6 +2527,18 @@ Global {9A073412-4B64-48EB-A346-A56DE6847CCC}.Release|x64.Build.0 = Release|Any CPU {9A073412-4B64-48EB-A346-A56DE6847CCC}.Release|x86.ActiveCfg = Release|Any CPU {9A073412-4B64-48EB-A346-A56DE6847CCC}.Release|x86.Build.0 = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|x64.ActiveCfg = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|x64.Build.0 = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|x86.ActiveCfg = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Debug|x86.Build.0 = Debug|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|Any CPU.Build.0 = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x64.ActiveCfg = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x64.Build.0 = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x86.ActiveCfg = Release|Any CPU + {2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2710,6 +2724,7 @@ Global {1BA5F72A-ED8E-48A8-8FD6-0F567BDCBD9E} = {E276EF69-669A-43E0-88AC-8ABB17A9C026} {FA726133-BC1C-D753-28C5-C9ACB44C0776} = {E276EF69-669A-43E0-88AC-8ABB17A9C026} {9A073412-4B64-48EB-A346-A56DE6847CCC} = {FA726133-BC1C-D753-28C5-C9ACB44C0776} + {2C37454E-8624-47B8-A09B-ADE201C2B04C} = {E276EF69-669A-43E0-88AC-8ABB17A9C026} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AB4EA6C9-5461-4024-BDC7-2AE0C3A85CD1} diff --git a/exercises/practice/relative-distance/.docs/instructions.md b/exercises/practice/relative-distance/.docs/instructions.md new file mode 100644 index 000000000..91dd5762b --- /dev/null +++ b/exercises/practice/relative-distance/.docs/instructions.md @@ -0,0 +1,39 @@ +# 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. + +~~~~exercism/note +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. +~~~~ + +[six-bacons]: https://en.m.wikipedia.org/wiki/Six_Degrees_of_Kevin_Bacon diff --git a/exercises/practice/relative-distance/.docs/introduction.md b/exercises/practice/relative-distance/.docs/introduction.md new file mode 100644 index 000000000..cb9fee6c7 --- /dev/null +++ b/exercises/practice/relative-distance/.docs/introduction.md @@ -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/ diff --git a/exercises/practice/relative-distance/.editorconfig b/exercises/practice/relative-distance/.editorconfig new file mode 100644 index 000000000..dae088791 --- /dev/null +++ b/exercises/practice/relative-distance/.editorconfig @@ -0,0 +1,141 @@ +############################### +# Core EditorConfig Options # +############################### + +; This file is for unifying the coding style for different editors and IDEs. +; More information at: +; https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017 +; https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2017 + +root = true + +[*] +indent_style = space + +[RelativeDistance.cs] +indent_size = 4 + +############################### +# .NET Coding Conventions # +############################### + +# Organize usings +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = true + +# this. preferences +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = always:suggestion +dotnet_style_readonly_field = true:suggestion + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion + +############################### +# Naming Conventions # +############################### + +# Style Definitions +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# Use PascalCase for constant fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.required_modifiers = const + +############################### +# C# Code Style Rules # +############################### + +# var preferences +csharp_style_var_for_built_in_types = true:none +csharp_style_var_when_type_is_apparent = true:none +csharp_style_var_elsewhere = true:none + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_constructors = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion +csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion + +# Pattern-matching preferences +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion + +# Null-checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# Expression-level preferences +csharp_prefer_braces = true:none +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +############################### +# C# Formatting Rules # +############################### + +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = false +csharp_new_line_before_members_in_anonymous_types = false +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true diff --git a/exercises/practice/relative-distance/.meta/Example.cs b/exercises/practice/relative-distance/.meta/Example.cs new file mode 100644 index 000000000..53df7ec9b --- /dev/null +++ b/exercises/practice/relative-distance/.meta/Example.cs @@ -0,0 +1,55 @@ +public class RelativeDistance +{ + private readonly Dictionary> relatives; + + public RelativeDistance(Dictionary familyTree) + { + Dictionary> parsed = new(); + foreach (var (parent, children) in familyTree) + { + var parentConnections = parsed.GetValueOrDefault(parent, []); + foreach (string child in children) + { + parentConnections.Add(child); + var childConnections = parsed.GetValueOrDefault(child, []) + .Union(children.Where(sibling => sibling != child)).ToHashSet(); + childConnections.Add(parent); + parsed[child] = childConnections; + } + + parsed[parent] = parentConnections; + } + relatives = parsed; + } + + public int DegreeOfSeparation(string personA, string personB) + { + if (!relatives.ContainsKey(personA) || !relatives.ContainsKey(personB)) + { + return -1; + } + + Queue<(string Person, int Degree)> queue = new(); + queue.Enqueue((personA, 0)); + HashSet visited = [personA]; + + while (queue.Count > 0) + { + var (currentPerson, degree) = queue.Dequeue(); + + if (currentPerson == personB) + { + return degree; + } + + var unvisited = relatives[currentPerson].Except(visited).ToHashSet(); + foreach (string neighbor in unvisited) + { + queue.Enqueue((neighbor, degree + 1)); + } + visited.UnionWith(unvisited); + } + + return -1; + } +} diff --git a/exercises/practice/relative-distance/.meta/Generator.tpl b/exercises/practice/relative-distance/.meta/Generator.tpl new file mode 100644 index 000000000..204effa7c --- /dev/null +++ b/exercises/practice/relative-distance/.meta/Generator.tpl @@ -0,0 +1,17 @@ +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + Dictionary familyTree = new() + { + {{- for entry in test.input.familyTree }} + { "{{ entry.key }}", [{{ for name in entry.value }}"{{ name }}"{{ if !for.last }}, {{ end }}{{ end }}] }{{ if !for.last }},{{ end }} + {{- end }} + }; + RelativeDistance rd = new(familyTree); + Assert.Equal({{ if test.expected }}{{ test.expected }}{{ else }}{{ -1 }}{{ end }}, rd.DegreeOfSeparation({{ test.input.personA | string.literal }}, {{ test.input.personB | string.literal }})); + } + {{ end -}} +} diff --git a/exercises/practice/relative-distance/.meta/config.json b/exercises/practice/relative-distance/.meta/config.json new file mode 100644 index 000000000..9ebe7bed8 --- /dev/null +++ b/exercises/practice/relative-distance/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "RelativeDistance.cs" + ], + "test": [ + "RelativeDistanceTests.cs" + ], + "example": [ + ".meta/Example.cs" + ] + }, + "blurb": "Given a family tree, calculate the degree of separation.", + "source": "vaeng", + "source_url": "https://github.com/exercism/problem-specifications/pull/2537" +} diff --git a/exercises/practice/relative-distance/.meta/tests.toml b/exercises/practice/relative-distance/.meta/tests.toml new file mode 100644 index 000000000..66c91ba09 --- /dev/null +++ b/exercises/practice/relative-distance/.meta/tests.toml @@ -0,0 +1,31 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[4a1ded74-5d32-47fb-8ae5-321f51d06b5b] +description = "Direct parent-child relation" + +[30d17269-83e9-4f82-a0d7-8ef9656d8dce] +description = "Sibling relationship" + +[8dffa27d-a8ab-496d-80b3-2f21c77648b5] +description = "Two degrees of separation, grandchild" + +[34e56ec1-d528-4a42-908e-020a4606ee60] +description = "Unrelated individuals" + +[93ffe989-bad2-48c4-878f-3acb1ce2611b] +description = "Complex graph, cousins" + +[2cc2e76b-013a-433c-9486-1dbe29bf06e5] +description = "Complex graph, no shortcut, far removed nephew" + +[46c9fbcb-e464-455f-a718-049ea3c7400a] +description = "Complex graph, some shortcuts, cross-down and cross-up, cousins several times removed, with unrelated family tree" diff --git a/exercises/practice/relative-distance/RelativeDistance.cs b/exercises/practice/relative-distance/RelativeDistance.cs new file mode 100644 index 000000000..fcf5c1d97 --- /dev/null +++ b/exercises/practice/relative-distance/RelativeDistance.cs @@ -0,0 +1,12 @@ +public class RelativeDistance +{ + public RelativeDistance(Dictionary familyTree) + { + throw new NotImplementedException("You need to implement this method."); + } + + public int DegreeOfSeparation(string personA, string personB) + { + throw new NotImplementedException("You need to implement this method."); + } +} diff --git a/exercises/practice/relative-distance/RelativeDistance.csproj b/exercises/practice/relative-distance/RelativeDistance.csproj new file mode 100644 index 000000000..a38815241 --- /dev/null +++ b/exercises/practice/relative-distance/RelativeDistance.csproj @@ -0,0 +1,18 @@ + + + enable + enable + Exe + net9.0 + true + + + + + + + + + + + \ No newline at end of file diff --git a/exercises/practice/relative-distance/RelativeDistanceTests.cs b/exercises/practice/relative-distance/RelativeDistanceTests.cs new file mode 100644 index 000000000..422e92f82 --- /dev/null +++ b/exercises/practice/relative-distance/RelativeDistanceTests.cs @@ -0,0 +1,234 @@ +public class RelativeDistanceTests +{ + [Fact] + public void Direct_parent_child_relation() + { + Dictionary familyTree = new() + { + { "Vera", ["Tomoko"] }, + { "Tomoko", ["Aditi"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(1, rd.DegreeOfSeparation("Vera", "Tomoko")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Sibling_relationship() + { + Dictionary familyTree = new() + { + { "Dalia", ["Olga", "Yassin"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(1, rd.DegreeOfSeparation("Olga", "Yassin")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Two_degrees_of_separation_grandchild() + { + Dictionary familyTree = new() + { + { "Khadija", ["Mateo"] }, + { "Mateo", ["Rami"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(2, rd.DegreeOfSeparation("Khadija", "Rami")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Unrelated_individuals() + { + Dictionary familyTree = new() + { + { "Priya", ["Rami"] }, + { "Kaito", ["Elif"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(-1, rd.DegreeOfSeparation("Priya", "Kaito")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Complex_graph_cousins() + { + Dictionary familyTree = new() + { + { "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"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(9, rd.DegreeOfSeparation("Dimitri", "Fabio")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Complex_graph_no_shortcut_far_removed_nephew() + { + Dictionary familyTree = new() + { + { "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"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(14, rd.DegreeOfSeparation("Lucia", "Jun")); + } + + [Fact(Skip = "Remove this Skip property to run this test")] + public void Complex_graph_some_shortcuts_cross_down_and_cross_up_cousins_several_times_removed_with_unrelated_family_tree() + { + Dictionary familyTree = new() + { + { "Aiko", ["Bao", "Carlos"] }, + { "Bao", ["Dalia"] }, + { "Carlos", ["Fatima", "Gustavo"] }, + { "Dalia", ["Hassan", "Isla"] }, + { "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"] } + }; + RelativeDistance rd = new(familyTree); + Assert.Equal(12, rd.DegreeOfSeparation("Wyatt", "Xia")); + } +} diff --git a/exercises/practice/relative-distance/packages.lock.json b/exercises/practice/relative-distance/packages.lock.json new file mode 100644 index 000000000..6b3387771 --- /dev/null +++ b/exercises/practice/relative-distance/packages.lock.json @@ -0,0 +1,170 @@ +{ + "version": 1, + "dependencies": { + "net9.0": { + "Exercism.Tests.xunit.v3": { + "type": "Direct", + "requested": "[0.1.0-beta1, )", + "resolved": "0.1.0-beta1", + "contentHash": "XjVtQWWxmHDDj7UMdkPKpBFFKnsW0tkBhlyJSfFFh+fWwGemyyJwJYhdsvWhiKKCY7zItB+mI/o0OQtOKQxUhA==", + "dependencies": { + "xunit.v3.extensibility.core": "1.1.0" + } + }, + "Microsoft.NET.Test.Sdk": { + "type": "Direct", + "requested": "[17.12.0, )", + "resolved": "17.12.0", + "contentHash": "kt/PKBZ91rFCWxVIJZSgVLk+YR+4KxTuHf799ho8WNiK5ZQpJNAEZCAWX86vcKrs+DiYjiibpYKdGZP6+/N17w==", + "dependencies": { + "Microsoft.CodeCoverage": "17.12.0", + "Microsoft.TestPlatform.TestHost": "17.12.0" + } + }, + "xunit.runner.visualstudio": { + "type": "Direct", + "requested": "[3.0.1, )", + "resolved": "3.0.1", + "contentHash": "lbyYtsBxA8Pz8kaf5Xn/Mj1mL9z2nlBWdZhqFaj66nxXBa4JwiTDm4eGcpSMet6du9TOWI6bfha+gQR6+IHawg==" + }, + "xunit.v3": { + "type": "Direct", + "requested": "[1.1.0, )", + "resolved": "1.1.0", + "contentHash": "1ckSz5GVswlM9TCk5bGdHOjnYwqAWjkeqxckoHawQIA8sTeuN+RCBUypCi5A/Um0XlczRx5TjAK5W6BbN0HLcQ==", + "dependencies": { + "xunit.analyzers": "1.20.0", + "xunit.v3.assert": "[1.1.0]", + "xunit.v3.core": "[1.1.0]" + } + }, + "Microsoft.Bcl.AsyncInterfaces": { + "type": "Transitive", + "resolved": "6.0.0", + "contentHash": "UcSjPsst+DfAdJGVDsu346FX0ci0ah+lw3WRtn18NUwEqRt70HaOQ7lI72vy3+1LxtqI3T5GWwV39rQSrCzAeg==" + }, + "Microsoft.CodeCoverage": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "4svMznBd5JM21JIG2xZKGNanAHNXplxf/kQDFfLHXQ3OnpJkayRK/TjacFjA+EYmoyuNXHo/sOETEfcYtAzIrA==" + }, + "Microsoft.Testing.Extensions.TrxReport.Abstractions": { + "type": "Transitive", + "resolved": "1.5.3", + "contentHash": "h34zKNpGyni66VH738mRHeXSnf3klSShUdavUWNhSfWICUUi5aXeI0LBvoX/ad93N0+9xBDU3Fyi6WfxrwKQGw==", + "dependencies": { + "Microsoft.Testing.Platform": "1.5.3" + } + }, + "Microsoft.Testing.Platform": { + "type": "Transitive", + "resolved": "1.5.3", + "contentHash": "WqJydnJ99dEKtquR9HwINz104ehWJKTXbQQrydGatlLRw14bmsx0pa8+E6KUXMYXZAimN0swWlDmcJGjjW4TIg==" + }, + "Microsoft.Testing.Platform.MSBuild": { + "type": "Transitive", + "resolved": "1.5.3", + "contentHash": "bOtpRMSPeT5YLQo+NNY8EtdNTphAUcmALjW4ABU7P0rb6yR2XAZau3TzNieLmR3lRuwudguWzzBhgcLRXwZh0A==", + "dependencies": { + "Microsoft.Testing.Platform": "1.5.3" + } + }, + "Microsoft.TestPlatform.ObjectModel": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "TDqkTKLfQuAaPcEb3pDDWnh7b3SyZF+/W9OZvWFp6eJCIiiYFdSB6taE2I6tWrFw5ywhzOb6sreoGJTI6m3rSQ==", + "dependencies": { + "System.Reflection.Metadata": "1.6.0" + } + }, + "Microsoft.TestPlatform.TestHost": { + "type": "Transitive", + "resolved": "17.12.0", + "contentHash": "MiPEJQNyADfwZ4pJNpQex+t9/jOClBGMiCiVVFuELCMSX2nmNfvUor3uFVxNNCg30uxDP8JDYfPnMXQzsfzYyg==", + "dependencies": { + "Microsoft.TestPlatform.ObjectModel": "17.12.0", + "Newtonsoft.Json": "13.0.1" + } + }, + "Newtonsoft.Json": { + "type": "Transitive", + "resolved": "13.0.1", + "contentHash": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==" + }, + "System.Collections.Immutable": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==" + }, + "System.Memory": { + "type": "Transitive", + "resolved": "4.6.0", + "contentHash": "OEkbBQoklHngJ8UD8ez2AERSk2g+/qpAaSWWCBFbpH727HxDq5ydVkuncBaKcKfwRqXGWx64dS6G1SUScMsitg==" + }, + "System.Reflection.Metadata": { + "type": "Transitive", + "resolved": "1.6.0", + "contentHash": "COC1aiAJjCoA5GBF+QKL2uLqEBew4JsCkQmoHKbN3TlOZKa2fKLz5CpiRQKDz0RsAOEGsVKqOD5bomsXq/4STQ==" + }, + "xunit.analyzers": { + "type": "Transitive", + "resolved": "1.20.0", + "contentHash": "HElev2E9vFbPxwKRQtpCSSzLOu8M/N9EWBCB37v7SRx6z4Lbj19FxfLEig3v9jiI6s4b0l2uena91nEsTWl9jA==" + }, + "xunit.v3.assert": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "4D+eM08ImfhA+zLbRzi8HA4qsT98zDxgaCD7vCg8yFesokKsgSsqWsAmImHFjVymGVhVS7WFGb19d6v1k9i0xQ==", + "dependencies": { + "System.Collections.Immutable": "8.0.0", + "System.Memory": "4.6.0" + } + }, + "xunit.v3.common": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "Cq55z8pC7fOkfj+3TB/YQ6OW96qWqxKiMd15CtkIl37VtV9EsiUL4B4HsR6VLJCzkk7cBiXQ1ABVIcp3TCm6HQ==", + "dependencies": { + "Microsoft.Bcl.AsyncInterfaces": "6.0.0" + } + }, + "xunit.v3.core": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "kXP/1d3jnQ2m4skcdM3gSMmubI6P747D6KVswzeedysgFkLj2xJlfo7p7slsmtEnp8BZb8X6D92Hssd/UtVPMw==", + "dependencies": { + "Microsoft.Testing.Platform.MSBuild": "1.5.3", + "xunit.v3.extensibility.core": "[1.1.0]", + "xunit.v3.runner.inproc.console": "[1.1.0]" + } + }, + "xunit.v3.extensibility.core": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "AeQbbYN001x0c+B9pqwml6jZPovHz8O/sOp7jmrjz90rUzz/QPal12SlHLKYszR44CMnW4MsDam3RYT5pkYUxw==", + "dependencies": { + "xunit.v3.common": "[1.1.0]" + } + }, + "xunit.v3.runner.common": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "Q81J0VPuu8fpF+/1CIjThqKKUjnqh0TQrLlD0iORkF75KdsOV+iGWT8c3AVuY96kDoxXxkTf0ZvJsK6o9osc1A==", + "dependencies": { + "xunit.v3.common": "[1.1.0]" + } + }, + "xunit.v3.runner.inproc.console": { + "type": "Transitive", + "resolved": "1.1.0", + "contentHash": "lX/4TwIJe9ysCd5dqLk/Doq8ieYaZGivgf95xR59wRuSV+nHzHnyhpjXfaPUp8nkncUH1rOmJ85o1KebipisXQ==", + "dependencies": { + "Microsoft.Testing.Extensions.TrxReport.Abstractions": "1.5.3", + "Microsoft.Testing.Platform": "1.5.3", + "xunit.v3.extensibility.core": "[1.1.0]", + "xunit.v3.runner.common": "[1.1.0]" + } + } + } + } +} \ No newline at end of file