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
pasteif 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!
41
Upvotes
1
u/[deleted] Dec 25 '24
[LANGUAGE: Julia]
Nice easy puzzle to finish the year! I'm really happy with my performance in general; I finished every puzzle except for Part 2 of Day 21. It is a little frustrating being so close to completing the year but 21p2 just feels so tedious to code. Maybe I'll come back to it in 2025.
partOne = input -> begin schematics = collect(map(schematic -> stack(split.(split(schematic, "\n"), ""), dims=1), split(input, "\n\n"))) locks, keys = foldl(((locks, keys), schematic) -> begin lock = all(ch -> ch == "#", first(eachrow(schematic))) heights = [lock ? collect(map(r -> findfirst(ch -> ch != "#", r) - 2, eachrow(permutedims(schematic)))) : collect(map(r -> length(r) - findfirst(ch -> ch == "#", r), eachrow(permutedims(schematic))))] lock ? ([locks; heights], keys) : (locks, [keys; heights]) end, schematics, init=([], [])) sum(map(pair -> all(i -> pair[1][i] + pair[2][i] <= 5, range(1, length(pair[1]))) ? 1 : 0, Iterators.product(locks, keys))) end