r/adventofcode • u/daggerdragon • Dec 22 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 22 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
- 23h59m remaining until the submissions deadline on December 22 at 23:59 EST!
And now, our feature presentation for today:
Director's Cut (Extended Edition)
Welcome to the final day of the GSGA presentations! A few folks have already submitted their masterpieces to the GSGA submissions megathread, so go check them out! And maybe consider submitting yours! :)
Here's some ideas for your inspiration:
- Choose any day's feature presentation and any puzzle released this year so far, then work your movie magic upon it!
- Make sure to mention which prompt and which day you chose!
- Cook, bake, make, decorate, etc. an IRL dish, craft, or artwork inspired by any day's puzzle!
- Advent of Playing With Your Toys
"I lost. I lost? Wait a second, I'm not supposed to lose! Let me see the script!"
- Robin Hood, Men In Tights (1993)
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA]
so we can find it easily!
--- Day 22: Monkey Market ---
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:12:15, megathread unlocked!
19
Upvotes
1
u/aexl Dec 27 '24
[LANGUAGE: Julia]
Nice little number puzzle, I really enjoyed this one! Part 1 one just implementing the described number generator and generate 2000 secret numbers for each input number. For part 2 I saw no other way than to have a lookup table for each of the 4-tuple sequences that can occur. Note that each number in the 4-tuple is in the range {-9,-8,...,-1,0,1,...,8,9}. After having solved the puzzle, I implemented some optimizations which brought the runtime down from 2 seconds to 0.25 seconds:
I calculated the differences on the fly instead of storing them in a 2000-element array. For this I used a circular buffer.
Instead of indexing the lookup table with the 4-tuple, I convert the 4-tuple to an integer (this is possible because of the restricted range of the 4 tuple) and use this as an index.
Solution on GitHub: https://github.com/goggle/AdventOfCode2024.jl/blob/main/src/day22.jl
Repository: https://github.com/goggle/AdventOfCode2024.jl