Skip to content

Commit

Permalink
[2019/6] solved
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 26, 2023
1 parent 3c9656e commit 50df928
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 2019/6/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
13 changes: 13 additions & 0 deletions 2019/6/example2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
K)YOU
I)SAN
41 changes: 41 additions & 0 deletions 2019/6/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from GhostyUtils import aoc
from collections import defaultdict


def bfs(graph, start, end):
visited = set()
frontier = [[start]]
while frontier:
path = frontier.pop(0)
node = path[-1]
if node == end:
return path

for new_node in graph[node]:
if new_node in visited:
continue
frontier.append(path + [new_node])
visited.add(new_node)


def main():
orbits = defaultdict(set)
satellites = set()
for orbit in aoc.read_lines():
body, satellite = orbit.split(')')
orbits[body].add(satellite)
orbits[satellite].add(body)
satellites.add(satellite)

total_orbits = 0
for satellite in satellites:
path = bfs(orbits, 'COM', satellite)
total_orbits += len(path) - 1
print('p1:', total_orbits)

path = bfs(orbits, 'YOU', 'SAN')
print('p2:', len(path)-2-1)


if __name__ == "__main__":
main()

0 comments on commit 50df928

Please sign in to comment.