advent-of-code-2019/day06.py

45 lines
549 B
Python
Raw Normal View History

2023-03-13 21:25:55 +01:00
from lib import Graph
def preproc(puzzle_input):
graph = Graph()
for line in puzzle_input.split('\n'):
sun, planet = line.split(')')
graph.add_edge(sun, planet)
return graph
def partI(graph):
return sum(w for node, w in graph.min_paths("COM").items())
def partII(graph):
return graph.min_path("SAN", "YOU") - 2
import solver
tests = solver.Tests()
tests.add("""COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L""", partI=42)
tests.add("""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""", partII=4)