-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
177 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Day 25: Snoverload | ||
""" | ||
|
||
import math | ||
|
||
import networkx as nx | ||
|
||
SAMPLE_INPUT = """ | ||
jqt: rhn xhk nvd | ||
rsh: frs pzl lsr | ||
xhk: hfx | ||
cmg: qnr nvd lhk bvb | ||
rhn: xhk bvb hfx | ||
bvb: xhk hfx | ||
pzl: lsr hfx nvd | ||
qnr: nvd | ||
ntq: jqt hfx bvb xhk | ||
nvd: lhk | ||
lsr: lhk | ||
rzs: qnr cmg lsr rsh | ||
frs: qnr lhk lsr | ||
""" | ||
|
||
|
||
def part1(data): | ||
""" | ||
>>> part1(SAMPLE_INPUT) | ||
54 | ||
""" | ||
gr = nx.Graph() | ||
for line in data.splitlines(): | ||
if not line: | ||
continue | ||
src, dsts = line.split(":", maxsplit=1) | ||
gr.add_edges_from((src, dst) for dst in dsts.split()) | ||
gr.remove_edges_from(nx.minimum_edge_cut(gr)) | ||
return math.prod( | ||
len(component) for component in nx.components.connected_components(gr) | ||
) | ||
|
||
|
||
parts = (part1,) |
Oops, something went wrong.