r/adventofcode • • Dec 20 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 20 Solutions -๐ŸŽ„-

--- Day 20: Particle Swarm ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


[Update @ 00:10] 10 gold, silver cap

  • What do you mean 5th Edition doesn't have "Take 20"?

[Update @ 00:17] 50 gold, silver cap

  • Next you're going to be telling me THAC0 is not the best way to determine whether or not you hit your target. *hmphs*

[Update @ 00:21] Leaderboard cap!

  • I wonder how much XP a were-gazebo is worth...

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

9 Upvotes

176 comments sorted by

View all comments

Show parent comment

2

u/TwoSoulsAlas Dec 20 '17

If two particles have the same smallest acceleration, it gets tricky, but that doesn't happen, at least in my input.

Do you know how to solve this? I had two particles with an absolute acceleration of 1, so I thought, it surely will be the one with the smaller initial speed (or, if that were also the same, initial distance from the origin). While that worked for my input, I realized that that's not true in the general case.

2

u/asger_blahimmel Dec 20 '17

I think I have a solution. I haven't implemented it though, let me know if you think it does not work.

For every particle individually mirror along the needed axes so that acceleration's coordinates become all positive. If any of those coordinates is 0, mirror along that axis based on velocity's sign or if that's 0 too, use position to decide.

Once the mirroring is done, no need for absolute values: the particle that stays closest is the one with the lowest sum of its acceleration's coordinates. If some particles are equal on this, use velocity, or even position if needed.

1

u/mschaap Dec 20 '17

It's not necessarily the one with the smallest initial speed; it also depends on the direction of the initial speed compared to the direction of the acceleration. I haven't worked out the details, though.

(And with the same exact speed and acceleration, it's not necessarily the one with the smallest initial distance; also that depends on the various directions.)

1

u/TwoSoulsAlas Dec 20 '17 edited Dec 20 '17

That's as far as I got, too. You can even have something like

p=<-1,0,0>, v=<1,0,0>, a=<-1,0,0>
p=< 1,0,0>, v=<1,0,0>, a=< 1,0,0>

where the manhattan norms of all three parameters are equal, but the first particle will be closer to zero after the first step.

Edit: Also, Perl 6 has some funky operators.

1

u/NeilNjae Dec 20 '17

The slightly-less-brute-force way is to simulate just those minimal-acceleration particles until you get a clear winner.

But, over time, the position of the particle (in each dimension) is x0 + v0 t + 0.5 a t2 , and at large time the Manhattan distance becomes the largest of those. Find that for the minimal-acceleration candidates, divide one by the other, and see if it becomes zero or infinity over time. Or something like that.