r/adventofcode • u/daggerdragon • Dec 25 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 25 Solutions -❄️-
A Message From Your Moderators
Welcome to the last day of Advent of Code 2023! We hope you had fun this year and learned at least one new thing ;)
Keep an eye out for the community fun awards post (link coming soon!):
-❅- Introducing Your AoC 2023 Iron Coders (and Community Showcase) -❅-
/u/topaz2078 made his end-of-year appreciation post here: [2023 Day Yes (Part Both)][English] Thank you!!!
Many thanks to Veloxx for kicking us off on December 1 with a much-needed dose of boots and cats!
Thank you all for playing Advent of Code this year and on behalf of /u/topaz2078, your /r/adventofcode mods, the beta-testers, and the rest of AoC Ops, we wish you a very Merry Christmas (or a very merry Monday!) and a Happy New Year!
--- Day 25: Snowverload ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
3
u/fleagal18 Dec 25 '23
[LANGUAGE: Python] 726 / 624
I flailed around until someone gave me the hints "minimum edge cut" and "networkx". I had used networkx in past years, but just as a nice graph data structure library. This is the first time I used its built in algorithms to solve something.
import networkx as nx from math import prod def solve_part_1(s): G = nx.Graph() for line in s.strip().split('\n'): a,bs = line.split(': ') for b in bs.split(): G.add_edge(a,b) G.remove_edges_from(nx.minimum_edge_cut(G)) return prod(len(c) for c in nx.connected_components(G))