-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvent_of_code_day6_2.py
More file actions
69 lines (56 loc) · 1.36 KB
/
advent_of_code_day6_2.py
File metadata and controls
69 lines (56 loc) · 1.36 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 6 18:55:28 2019
@author: luis
"""
def create_map(array):
orbits={}
for i in array:
i=i.split(")")
if i[1] in orbits.keys():
j=orbits[i[1]]
j.append(i[0])
orbits[i[1]]=j
else:
orbits[i[1]]=[i[0]]
return orbits
def create_map2(array):
orbits={}
for i in array:
i=i.split(")")
if i[0] in orbits.keys():
j=orbits[i[0]]
j.append(i[1])
orbits[i[0]]=j
else:
orbits[i[0]]=[i[1]]
return orbits
def total_orbits2(orbits,i):
total=0
if i not in orbits.keys():
return 0
else:
total=len(orbits[i])
for j in orbits[i]:
total+=total_orbits2(orbits,j)
return total
def total_orbits(orbits):
total=0
for i in orbits.keys():
total+=total_orbits2(orbits,i)
return total
def find_route(objects_orbiting,orbit_object):
you=object_orbiting["YOU"]
santa=objects_orbiting["SAN"]
total=0
f=open("input_day6.txt","r")
array=f.readlines()
f.close()
for i in range(len(array)):
array[i]=array[i].split('\n')[0]
objects_orbiting=create_map(array)
orbit_object=create_map2(array)
total=total_orbits(objects_orbiting)
total2=total_orbits(orbit_object)
print(total,total2)