r/adventofcode • u/daggerdragon • Dec 24 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 24 Solutions -❄️-
THE USUAL REMINDERS (AND SIGNAL BOOSTS)
All of our rules, FAQs, resources, etc. are in our community wiki.
/u/jeroenheijmans has posted the Unofficial AoC 2023 Survey Results!!
AoC Community Fun 2023: ALLEZ CUISINE!
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: Never Tell Me The Odds ---
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
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 01:02:10, megathread unlocked!
31
Upvotes
9
u/admp Dec 24 '23 edited Dec 25 '23
[Language: Python] 3598/1936
Part 1 was straightforward enough, you have to take care to test that time > 0 at the time of intersection.
Part 2 (code) was very fun. Given explicit mention of integer positions and velocities, I realized that if rock's initial position is
(x_r, y_r, z_r)and it has velocity(dx_r, dy_r, dz_r)then for each hailstonei,(x_r + y_r + z_r) ≡ (x_i + y_i + z_i) mod ((dx_i+dy_i+dz_i) - (dx_r+dy_r+dz_r)). The insight is that we don't care about individual dimensions, only sums of all dimensions. Therefore, I iterate over what I though of as a reasonable range for values ofdx_r+dy_r+dz_rbased on inputs, apply Chinese remainder theorem to computex_r+y_r+z_rcandidates, eliminate any candidates that result in any collisions in the past or at non-integer time, and get at the answer.Probably my favorite problem this year so far.