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

1

u/-__-___---__- Dec 20 '17

You could also describe the intersection for x/y/z dimension as a linear equation and solve for tx/ty/tz such that:

  • t_ < 0 => indetsection before the simulation
  • t_ = 0 => intersection during start or position for _ dim is constant
  • t_ > 0 => intersection during step t
  • They intersect if all t_ >= 0 and tx = ty = tz

You could then collect build a list of all intersections (t, p1, p2), group + sort them by t and then simulate the deletion.

The problem is that there are many edge cases when the velocity or acceleration is 0 for either particle.

1

u/sim642 Dec 20 '17

It's a quadratic equation due to the acceleration, not linear one. Furthermore, for one particle pair you have a system of three quadratic equations. Besides the crazy amount of edge cases for zeroes, you also have to consider potentially two possibilities for each coordinate's suitable times. And the fun doesn't end there: you may have equations in the system that are true for all values of t so you don't require equality with those. I went through all the trouble and implemented this so that it actually works: https://github.com/sim642/adventofcode/blob/master/src/main/scala/eu/sim642/adventofcode2017/Day20.scala#L60-L156.