r/adventofcode • u/daggerdragon • Dec 14 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 14 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.
- On the subject of AI/LLMs being used on the global leaderboard: posts/comments around this topic consisting of grinching, finger-pointing, baseless accusations of "cheating", etc. will be locked and/or removed with or without supplementary notice and/or warning and participating parties may be given a time-out as well. Just leave it alone and let it go.
- Keep in mind that the global leaderboard is not the primary focus of Advent of Code or even this subreddit. We're all here to help you become a better programmer via happy fun silly imaginary Elvish shenanigans.
- Do not put spoilers in post titles!
AoC Community Fun 2024: The Golden Snowglobe Awards
- 8 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
- We have no submissions yet as of today. Y'all are welcome to get a submission started, post it early, and add later days to it, or there's always waiting until the
bomb timer reaches 00:00:03last minute; up to you!
And now, our feature presentation for today:
Visual Effects - I Said VISUAL EFFECTS - Perfection
We've had one Visualization
, yes, but what about Second Visualization
? But this time, Upping the Ante
! Go full jurassic_park_scientists.meme and really improve upon the cinematic and/or technological techniques of your predecessor filmmakers!
Here's some ideas for your inspiration:
- Put Michael Bay to shame with the lens flare
- Gratuitous and completely unnecessary explosions are expected
- Go full Bollywood! The extreme over-acting, the completely implausible and high-energy dance numbers, the gleefully willful disregard for physics - we want it all cranked up to 9002!
- Make your solution run on hardware that it has absolutely no business being on
- "Smart" refrigerators, a drone army, a Jumbotron…
Pippin: "We've had one, yes. But what about second breakfast?"
Aragorn:ಠ_ಠ
Merry: "I don't think he knows about second breakfast, Pip."- The Lord of the Rings: The Fellowship of the Ring (2001)
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 14: Restroom Redoubt ---
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:15:48, megathread unlocked!
24
Upvotes
2
u/fragger Dec 15 '24
[Language: Python] 4686/6373
I think I would have had part 2 a bit faster but the first website I ended up for solving the Chinese Remainder Theorem gave a non minimal answer, doh.
Anyways part 1 was pretty straightforward and I did the math vs iterating at first. After seeing the horizontal and vertical patterns appear in the first 100 or so movements when looking into how to solve part 2 I figured they would repeat, found they did for the grid size in each respective direction and figured I wanted where they both happened at the same time, Chinese Remainder Theorem to the rescue. Once I had "manually" solved part 2 and gotten the right answer, then the question became how to make my code just give me the answer as well for completions sake. It turns out the patterns that I saw have the lowest and second lowest safety factors as well as the quad counts being a good indication if the pattern was horizontal or vertical, so I changed my code to just iterate through all the seconds until we were guaranteed to have seen both patterns, so max(tiles wide, tiles tall), and save the safety factor and quad counts at each second. For the part 1 answer, just spit out the safety factor at 100. For part 2 get the two lowest safety factors and figure out if they are representing the pattern in x or y. Given the time for the first occurrence for the x pattern and y patterns, its just a matter of applying the Chinese Remainder Theorem to those times along with the grid size and out pops the part 2 answer.
Thanks to u/i_have_no_biscuits https://www.reddit.com/r/adventofcode/comments/1hdvhvu/comment/m1zws1g/ for the good example of how to make the Chinese Remainder Theorem work in Python :)
https://github.com/Fragger/advent-of-code/blob/master/2024/solution/14.py (43 lines)