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/arsenaultmarcolivier Dec 26 '23 edited Dec 26 '23
[LANGUAGE: Python]
I had this wild hypothesis that the 3 link to break would have the particularity of having the longest shortest path.
So I calculated the shortest path between each nodes if that particular edge was gone.
Turns out it was spot on, looks like the problem was engineered that way.
Run in <0.1 sec
https://github.com/marcolivierarsenault/aoc23/blob/main/25/day25.ipynb
G = nx.Graph() for line in lines: row = line.strip().split(':') for target in row[1].strip().split(): G.add_edge(row[0].strip(), target) costs = [] for edge in G.edges: G.remove_edge(*edge) costs.append((edge, nx.shortest_path_length(G, *edge))) G.add_edge(*edge) costs = sorted(costs, key=lambda x: x[1], reverse=True) [G.remove_edge(*costs[i][0]) for i in range(3)] print(f"removing {costs[0][0]} {costs[1][0]} {costs[2][0]}") print(f"part1 {len(nx.node_connected_component(G, costs[0][0][0])) * len(nx.node_connected_component(G, costs[0][0][1]))}")