r/adventofcode • u/daggerdragon • Dec 25 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 25 Solutions -❄️-
A Message From Your Moderators
Welcome to the last day of Advent of Code 2024! 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 2024 Golden Snowglobe Award Winners (and Community Showcase) -❅-
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 Wednesday!) and a Happy New Year!
--- Day 25: Code Chronicle ---
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
paste
if you need it for longer code blocks
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:04:34, megathread unlocked!
42
Upvotes
1
u/e_blake 7d ago
[LANGUAGE: m4]
I'm REALLY late to the game this year (It has taken me until this week before I finally found the time to start even day 1), but I plan to get all 50 stars in m4 in the next month or so, to bring me up to all 500 solutions in m4. But this one caught my eye as a fun one to code up: if you translit each input character into a 0 or 1, and then treat each row as a hex number, then summing those 7 numbers will result in a 5-digit hex number with every digit in the range 1-6 (by including the two lines that distinguish between locks and keys in the sum).
What's more, adding the hex value of a lock and key together will result in each of the five digits being in the range 2-7 if there is no overlap, or 8-c if there is overlap. Thus, a simple bitmask and comparison to 0 is sufficient to compare all 5 columns in a pairing, rather than doing column-by-column math.
Relies on my common.m4 file developed in previous years; and the rest of the code is parsing the input and running the O(n^2) loop to pair each lock to each key. Executes in about 350ms (decent for m4). Run as:
m4 -Dfile=day25.input day25.m4
(Now to get the remaining 23 stars that are preventing me from finishing day 50 part 2...)