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

solve Succession with C# #1222

Open
Mahsa1996 opened this issue Feb 18, 2022 · 4 comments
Open

solve Succession with C# #1222

Mahsa1996 opened this issue Feb 18, 2022 · 4 comments

Comments

@Mahsa1996
Copy link

The king in Utopia has died without an heir. Now several nobles in the country claim the throne. The country law states that if the ruler has no heir, the person who is most related to the founder of the country should rule.

To determine who is most related we measure the amount of blood in the veins of a claimant that comes from the founder. A person gets half the blood from the father and the other half from the mother. A child to the founder would have 1/2 royal blood, that child’s child with another parent who is not of royal lineage would have 1/4 royal blood, and so on. The person with most blood from the founder is the one most related.

Input
The first line contains two integers, N (2 ≤ N ≤ 50) and M (2 ≤ M ≤ 50).

The second line contains the name of the founder of Utopia.

Then follows N lines describing a family relation. Each such line contains three names, separated with a single space. The first name is a child and the remaining two names are the parents of the child.

Then follows M lines containing the names of those who claims the throne.

All names in the input will be between 1 and 10 characters long and only contain the lowercase English letters ’a’-’z’. The founder will not appear among the claimants, nor be described as a child to someone else.

Output
A single line containing the name of the claimant with most blood from the founder. The input will be constructed so that the answer is unique.

The family relations may not be realistic when considering sex, age etc. However, every child will have two unique parents and no one will be a descendent from themselves. No one will be listed as a child twice.

@Mahsa1996
Copy link
Author

can you help me to resolved problem with C#

@6pac
Copy link

6pac commented Feb 19, 2022

The joy in in solving it yourself. However if you want some pointers:

  • make yourself a sample dataset
  • write the code to put the 'three people in the family realation' dataset into a List where Relation has string properties Parent1Name, Parent2Name and ChildName and a float Relatedness score for each, and a bool Complete for each
  • now you can start with the name of the founder and iterate throught the List and find the founder's children and assign their score and mark them complete
  • then repeatedly iterate the list and find anyone not complete but with a relatedness score and propagate this to any children
  • once you can't find anyone with not complete but with a relatedness score, you are done
  • it's trivial from here, just get the person in dataset M with the highest score
  • once you get it working, throw as many weird variations into you dataset as possible and check the program copes (or write a series of tests, if you're a fan of TDD)

@LucasJuan
Copy link

Anyone have a solution for this exercise? My main goal is about the search how to proceed

@LucasJuan
Copy link

LucasJuan commented Oct 20, 2022

some approaches
[https://github.com/LucasJuan/Programming_test_Kattis_Peanuts_And_Sucession]
[https://github.com/LucasJuan/Programming_test_Kattis_Sucessor_notFinished]

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

No branches or pull requests

3 participants