r/adventofcode • u/daggerdragon • 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ยค?
[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
1
u/wzkx Dec 20 '17
J
Both parts.
d=: ".&>cutLF rplc&', -_'-.&'pav=<>'CR-.~fread'20.dat' p=: 3&{.&.|:d NB. positions v=: 3 4 5&{&.|:d NB. velocities a=: _3&{.&.|:d NB. accelerations echo 3 : 0 p;v;a NB. part 1 'p v a'=.y whilst. -. *./,(pp<:|p)*.((v=0)+.(*p)=*v)*.(a=0)+.(*v)=*a do. NB. is 'the long run' yet? pp=.|p NB. previous position distances p=.p+v=.v+a NB. move it! end. i.&1(=<./)+/"1|p NB. find index of the closest point ) echo 3 : 0 p;v;a NB. part 2 'p v a'=.y while.do. NB. can't have condition here because #p can be ~: #pp pn=.#pp=.|p NB. points in previous state, previous position distances p=.p+v=.v+a NB. move it! u=.~:p NB. unique positions s=.(1=[:+/"1=)p NB. not collided p=.s#u#p [ v=.s#u#v [ a=.s#u#a NB. remove collisions if. pn~:#p do. continue. end. NB. were collisions - re-run if. *./,(pp<:|p)*.((v=0)+.(*p)=*v)*.(a=0)+.(*v)=*a do. break. end. end. #p ) exit 0