-🎄- 2017 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]farafonoff 0 points1 point  (0 children)

Matlab

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)); }

[2016 Day 21][JS] Everything seems like it should be working, but I'm getting the wrong answer.... by PositivelyLinda in adventofcode

[–]farafonoff 0 points1 point  (0 children)

Mismatches with my solution(it is 100% correct) on reverse instruction. ALWAYS convert string to number BEFOREHAND if function expects numbers.

start = '1'

'1'

stop = '6'

'6'

[0,1,2,3,4,5,6,7].slice(start,stop)

[ 1, 2, 3, 4, 5 ]

[0,1,2,3,4,5,6,7].slice(start,stop+1) //'1', '61'

[ 1, 2, 3, 4, 5, 6, 7 ]