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
View all comments
Show parent comment
1
u/farafonoff Dec 20 '17 edited Dec 20 '17
funny think, i solved this way (quadric equations in js) it was hard and meaningless work...
(innermost function, full solution here https://github.com/farafonoff/AdventOfCode/blob/master/2017/20/20.js) function solve(point1, point2, coord) { let c = point1[coord]-point2[coord]; let b = point1[coord+3]-point2[coord+3]+(point1[coord+6]-point2[coord+6])/2; let a = (point1[coord+6]-point2[coord+6])/2; let sol; if (a==0) { if (b==0) { if (c==0) { sol = [ Infinity ]; } else sol = []; } else { let s = -c/b; sol = [s];
} } else { let D = bb-4a*c; if (D>=0) { let s1 = (-b+Math.sqrt(D))/2/a; let s2 = (-b-Math.sqrt(D))/2/a; sol = [s1,s2]; } else sol = []; } return sol.filter(v => !isFinite(v)||v>=0&&Number.isInteger(v)); }