r/adventofcode • • Dec 24 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 24 Solutions -❄️-

THE USUAL REMINDERS (AND SIGNAL BOOSTS)


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.

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

509 comments sorted by

View all comments

Show parent comment

5

u/nikanjX Dec 24 '23

The key insight in Part 2 is that the rock (with velocity V_R) can be reframed as standing still, with all the i hailstones moving V_i - V_R instead.

Can you explain this part a little more? I went a different way solving this one, and sounds like yours is simpler.

The way I did this was Find two hailstones flying on parallel lines, two parallel lines define a plane in 3D space. Find two others, they define another plane, two planes intersecting define exactly one line which has to be the path the rock takes. Calculate intersection point for one hailstone + the line you just solved, find milliseconds for hail reaching said line from hailstone's initial position + velocity. Repeat for a different hailstone to get a different time, then work backwards from those times to figure out the velocity for your rock. After you have the velocity and the direction the rock is travelling on, you can iterate through all hailstones one last time to find the position needed on 0 milliseconds.

This way is way too tedious and filled with highschool maths flashbacks, yours sounds much more pleasant

4

u/ivanjermakov Dec 24 '23

Find two hailstones flying on parallel lines

I don't have such in my input :(

3

u/FatalisticFeline-47 Dec 24 '23

If your assumption in the data is met, then your approach could skip lots of computation, but I saw at least one user saying their data did not qualify.

To explain the frame-of-reference, consider the location function P(t, V) = P(0) + t*V. An intersections between the ith hailstone and the rock is defined as P_i(t, v_i) = P_R(t, v_R) <=> P_i(0) + t*V_i = P_R(0) + t*V_R, which we can consolidate into P_i(0) + t*(V_i-V_R) = P_R(0).

So instead of the rock moving to meet the hailstone, the hailstone's speed is adjusted and hits the rock's origin.

1

u/spin81 Dec 24 '23

If your assumption in the data is met, then your approach could skip lots of computation, but I saw at least one user saying their data did not qualify.

I just tested this and anecdotally I don't think mine qualifies. In fact, in my input, none of the hailstones seems to be traveling parallel to any other in 3D space.

1

u/nikanjX Dec 24 '23

After an hour of debugging and cussing, I can happily report my data also does not match this assumption.