My Advent of Code solutions in Python.
kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code
python
1import fileinput
2from utils import mul
3
4try:
5 import networkx as nx
6except ImportError:
7 print("Solution requires NetworkX (`pip install networkx`)")
8 import sys
9 sys.exit()
10
11# Parse problem input.
12graph = nx.Graph()
13
14for line in fileinput.input():
15 src, rest = line.strip().split(': ')
16 graph.add_node(src)
17 for dest in rest.split():
18 graph.add_edge(src, dest)
19
20# Solve part 1.
21for a, b in nx.minimum_edge_cut(graph):
22 graph.remove_edge(a, b)
23
24print("Part 1:", mul(len(c) for c in nx.connected_components(graph)))