-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.py
43 lines (35 loc) · 852 Bytes
/
6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
with open('../6.txt') as f:
orbits = dict(reversed(x[:-1].split(')')) for x in f)
count = 0
for body, parent in orbits.items():
count += 1
while parent != 'COM':
count += 1
parent = orbits[parent]
print(count)
parent = orbits['SAN']
san_line = [parent]
while parent != 'COM':
parent = orbits[parent]
san_line.append(parent)
parent = orbits['YOU']
you_line = [parent]
while parent != 'COM':
parent = orbits[parent]
you_line.append(parent)
for san, you in zip(reversed(san_line), reversed(you_line)):
if san == you:
common = san_line.pop()
you_line.pop()
else:
break
count = 0
parent = orbits['SAN']
while parent != common:
count += 1
parent = orbits[parent]
parent = orbits['YOU']
while parent != common:
count += 1
parent = orbits[parent]
print(count)