My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2023/25

+24
+24
2023/day25.py
··· 1 + import fileinput 2 + from utils import mul 3 + 4 + try: 5 + import networkx as nx 6 + except ImportError: 7 + print("Solution requires NetworkX (`pip install networkx`)") 8 + import sys 9 + sys.exit() 10 + 11 + # Parse problem input. 12 + graph = nx.Graph() 13 + 14 + for 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. 21 + for a, b in nx.minimum_edge_cut(graph): 22 + graph.remove_edge(a, b) 23 + 24 + print("Part 1:", mul(len(c) for c in nx.connected_components(graph)))