I would like to give some feedback about ...
From: https://checkio.org/mission/find-friends/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
for python3:
when I run my code, the result is:
test 7/7, true
but in my local environment, the result is false, and that's exactly the right answer.
I have no idea what happened.
my_network = {}
def connect_us(target, friends):
next_one = []
def do_check(x, y):
if y in x:
my_network[x] = 1
for n in x.split('-'):
friends.add(n)
next_one.append(n)
next_one.remove(y)
if target:
for a_b, v in my_network.items():
if v == 1: continue
if isinstance(target, str):
do_check(a_b, target)
elif isinstance(target, list):
for t in target:
do_check(a_b, t)
return connect_us(next_one, friends)
else:
return friends
def check_connection(network, first, second):
for i in network:
my_network[i] = 0
friends = set()
f1 = connect_us(first, friends)
#print('f1 = {0}'.format(f1))
#print('my_network = {0}'.format(my_network))
for i in network:
my_network[i] = 0
friends = set()
f2 = connect_us(second, friends)
#print('f2 = {0}'.format(f2))
#print('my_network = {0}'.format(my_network))
return True if f1 & f2 else False
if __name__ == '__main__':
r = check_connection(
['base-night', 'scout1-night', 'pingin-sscout', 'sscout-scout1', 'dr101-pingin', 'sscout-base',
'dr101-sscout', 'pingin-night', 'pingin-scout1', 'scout1-dr101', 'dr101-night'],
"pingin", "base")
print r
for python2:
test 1 was failed also, please check it.
Created at: 2016/07/14 09:36; Updated at: 2016/07/15 01:51