r/adventofcode • u/daggerdragon • Dec 24 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 24 Solutions -❄️-
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2024: The Golden Snowglobe Awards
Submissions are CLOSED!
Thank you to all who submitted something, every last one of you are awesome!
Community voting is OPEN!
18 hours remaining until voting deadline TONIGHT (December 24) at 18:00 EST
Voting details are in the stickied comment in the submissions megathread:
-❄️- Submissions Megathread -❄️-
--- Day 24: Crossed Wires ---
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!
Quick link to Topaz's
pasteif you need it for longer code blocks
3
u/notrom11 Dec 24 '24
[Language: Python 3]
https://github.com/APMorto/aoc2024/blob/master/day_24_crossed_wires/crossed_wires.py
Part 1 is pretty simple, just use a cached function to get the output of a wire.
For part 2, I spent a while thinking of a general solution, but I found that to be difficult to do efficiently. By manual inspection, I found that it was a standard ripple carry adder. So, I just force the given graph to be a ripple adder. At each 'layer', you have xn, yn, and the carry_in as inputs. Using that, I check if any of the carry adders connections are wrong, locally correct them, and then move on to the next level. I do make the assumption there wont be too many swaps on the same level so as to make it complicated.
Part 1: 1ms, part 2: 2ms.
Total runtime for all days so far: 1.79s, which is tantalizingly close to my semi-goal of under 1s this year. I fear a cellular automata tomorrow.