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

fix: relative distance #2545

Merged
merged 3 commits into from
Mar 26, 2025
Merged

fix: relative distance #2545

merged 3 commits into from
Mar 26, 2025

Conversation

vaeng
Copy link
Contributor

@vaeng vaeng commented Mar 13, 2025

fix errors in concept.

Here is a mermaid diagram of the last part:

 graph TD;
  Aiko --> Bao;
  Bao --> Carlos;
  Aiko --> Carlos;
  Carlos --> Bao;
  Bao --> Dalia;
  Carlos --> Fatima;
  Fatima --> Gustavo;
  Carlos --> Gustavo;
  Gustavo --> Fatima;
  Dalia --> Hassan;
  Hassan --> Isla;
  Dalia --> Isla;
  Isla --> Hassan;
  Fatima --> Khadija;
  Khadija --> Liam;
  Fatima --> Liam;
  Liam --> Khadija;
  Gustavo --> Mina;
  Hassan --> Noah;
  Noah --> Olga;
  Hassan --> Olga;
  Olga --> Noah;
  Isla --> Pedro;
  Javier --> Quynh;
  Quynh --> Ravi;
  Javier --> Ravi;
  Ravi --> Quynh;
  Khadija --> Sofia;
  Liam --> Tariq;
  Tariq --> Uma;
  Liam --> Uma;
  Uma --> Tariq;
  Mina --> Viktor;
  Viktor --> Wang;
  Mina --> Wang;
  Wang --> Viktor;
  Noah --> Xiomara;
  Olga --> Yuki;
  Pedro --> Zane;
  Zane --> Aditi;
  Pedro --> Aditi;
  Aditi --> Zane;
  Quynh --> Boris;
  Ravi --> Celine;
  Sofia --> Diego;
  Diego --> Elif;
  Sofia --> Elif;
  Elif --> Diego;
  Tariq --> Farah;
  Uma --> Giorgio;
  Viktor --> Hana;
  Hana --> Ian;
  Viktor --> Ian;
  Ian --> Hana;
  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;
Loading

And here is a python script to parse json to mermaid for easy comparison:

import json
import re

def json_to_mermaid(family_tree):
   """Converts a JSON family tree to a Mermaid graph string."""
   mermaid_lines = ["graph TD;"]
   for parent, children in family_tree.items():
       for child in children:
           mermaid_lines.append(f"  {parent} --> {child};")
           for other_children in children:
               if other_children != child:
                   mermaid_lines.append(f"  {child} --> {other_children};")
   return "\n".join(mermaid_lines)

def mermaid_to_json(mermaid_str):
   """Converts a Mermaid graph string to a JSON family tree."""
   family_tree = {}
   lines = mermaid_str.split("\n")

   for line in lines:
       match = re.match(r"\s*([\w\d]+)\s*-->\s*([\w\d]+);", line)
       if match:
           parent, child = match.groups()
           if parent not in family_tree:
               family_tree[parent] = []
           family_tree[parent].append(child)

   return family_tree

# Example usage:
family_tree_json =  {
         "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"]
       }

# Convert JSON to Mermaid
mermaid_graph = json_to_mermaid(family_tree_json)
print("Mermaid Graph:\n", mermaid_graph)

# Convert Mermaid back to JSON
reconstructed_json = mermaid_to_json(mermaid_graph)
#print("\nReconstructed JSON:\n", json.dumps(reconstructed_json, indent=2))

@vaeng
Copy link
Contributor Author

vaeng commented Mar 13, 2025

@jiegillet
Can you please confirm with your elixir solution?

My Cpp backs up your results and the changed tests.

@ErikSchierboom
This would be the force-push fix.

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @jiegillet could check if the data is now correct? Once confrmed, I'll force merge this.

@jiegillet
Copy link
Contributor

Data-wise, I get the same results, however, that means that we are using the sibling rule (distance between siblings is 1) which is not really standard when talking about tree distances, so I really think that should be explicitly mentioned in the instructions. I understand if we want to do it in a separate PR though.

@ErikSchierboom
Copy link
Member

Data-wise, I get the same results, however, that means that we are using the sibling rule (distance between siblings is 1) which is not really standard when talking about tree distances, so I really think that should be explicitly mentioned in the instructions. I understand if we want to do it in a separate PR though.

Oh, I would also not have thought it worked like that. Is that standard when doing the distance for families?

@vaeng
Copy link
Contributor Author

vaeng commented Mar 13, 2025

Is that standard when doing the distance for families?

No, it is not standard. If we make it standard, your uncle by marriage would have no relation to you in this exercise.
I opted to do it how it is worded, to make it more interesting (for me, at least).

@ErikSchierboom
Copy link
Member

Okay I'm totally fine with that.

@vaeng vaeng requested a review from a team as a code owner March 26, 2025 10:57
@vaeng
Copy link
Contributor Author

vaeng commented Mar 26, 2025

I added a note. What do you think @jiegillet

@vaeng
Copy link
Contributor Author

vaeng commented Mar 26, 2025

Let's force push. The tests are fixed, if there are more discussions about the text, that could go into a normal commit I would say.

@ErikSchierboom
Copy link
Member

Done

@ErikSchierboom ErikSchierboom merged commit ad7e332 into main Mar 26, 2025
6 of 7 checks passed
@ErikSchierboom ErikSchierboom deleted the fix--realtive-distance branch March 26, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants