Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple one solution in Clear category for What Is Wrong With This Family? by kalauroma7997
def is_family(tree):
DADS, SONS = [], []
for dad, son in tree:
DADS += [dad]
if son in SONS:
return False
SONS += [son]
if [son, dad] in tree:
return False
fatherless = 0
for dad in set(DADS):
if dad not in SONS:
fatherless += 1
if fatherless > 1:
return False
return True
if __name__ == "__main__":
#These "asserts" using only for self-checking and not necessary for auto-testing
assert is_family([
['Logan', 'Mike']
]) == True, 'One father, one son'
assert is_family([
['Logan', 'Mike'],
['Logan', 'Jack']
]) == True, 'Two sons'
assert is_family([
['Logan', 'Mike'],
['Logan', 'Jack'],
['Mike', 'Alexander']
]) == True, 'Grandfather'
assert is_family([
['Logan', 'Mike'],
['Logan', 'Jack'],
['Mike', 'Logan']
]) == False, 'Can you be a father for your father?'
assert is_family([
['Logan', 'Mike'],
['Logan', 'Jack'],
['Mike', 'Jack']
]) == False, 'Can you be a father for your brather?'
assert is_family([
['Logan', 'William'],
['Logan', 'Jack'],
['Mike', 'Alexander']
]) == False, 'Looks like Mike is stranger in Logan\'s family'
print("Looks like you know everything. It is time for 'Check'!")
Aug. 12, 2020
Comments: