Created
August 27, 2014 09:08
-
-
Save chansuke/f065abea9259cce2f0cb to your computer and use it in GitHub Desktop.
Check iO - How to find friends
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_connection(network, first, second): | |
path = {first} | |
check = 0 | |
while (len(path) > check): | |
check = len(path) | |
for i in network: | |
one,two = i.split("-") | |
if one in path or two in path: | |
path.add(one) | |
path.add(second) | |
else: | |
return second in path | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment