narimiran / checkio Goto Github PK
View Code? Open in Web Editor NEWmy solutions for the problems on checkio.org
my solutions for the problems on checkio.org
I got a problem in this:
checkio
and found your solution here.
That isn't working now, but gave me a lot of inspiration ๐ , Thanks a lot.
Some new situations in checkio here may assert error:
` assert is_family([["Logan","Mike"],["Alexander","Jack"],["Jack","Logan"]]) == True, '!'
assert is_family([["Logan","Mike"],["Alexander","Jack"],["Jack","Alexander"]]) == False, '!'
assert is_family([["Logan","William"],["William","Jack"],["Jack","Mike"],["Mike","Alexander"]]) == True, '!'
assert is_family([["Logan","William"],["Mike","Alexander"],["William","Alexander"]]) == False, '!'`
Improved new solution here.
def is_family(tree):
tree.sort()
# son check, every one can be son just 1 time
son = []
for f_s in tree:
son.append(f_s[1])
if len(son) != len(set(son)):
print('before loop, end: you can\'t be two man\'s son')
return False
# daddy check, every one should be daddy or have a daddy
family = tree[0]
tree = tree[1:]
loop = 0
while True:
if loop > len(tree) or len(tree)==0:
break
if tree[0][0] in family and tree[0][1] not in family:
family.append(tree[0][1])
tree = tree[1:]
loop = 0
elif tree[0][1] in family and tree[0][0] not in family:
family.append(tree[0][0])
tree = tree[1:]
loop = 0
else:
tree.append(tree[0])
tree = tree[1:]
loop += 1
print('after loop, end, this left:',tree)
return not len(tree)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.