Skip to content
Snippets Groups Projects
Commit 033b2f5e authored by Mark Jeeninga's avatar Mark Jeeninga
Browse files

Day 7 Mark

parent 59e65078
No related branches found
No related tags found
No related merge requests found
range = x => [...Array(x).keys()]
totals = input.split("\n").map(x => Number(x.split(":")[0]))
numbers = input.split("\n").map(x => x.split(": ")[1].split(" ").map(Number))
output1 = numbers.map((x,k) => range(2**(x.length-1)).reduce((y,z) => y + (totals[k] == x.reduce((a,b,i) => 2**(i-1) & z ? a+b : a*b)) > 0 ? totals[k] : 0, 0)).reduce((x,y) => x+y)
concat = (a,b) => Number(a.toString() + b.toString())
base3 = (x,l) => x.toString(3,l).padStart(l,'0').split('').map(Number)
output2 = numbers.map((x,k) => range(3**(x.length-1)).map(y=> base3(y,x.length-1)).reduce((y,z) => y + (totals[k] == x.reduce((a,b,i) => (z[i-1] ? (z[i-1] == 2 ? concat(a,b) : z[i-1] == 1 ? a*b : a+b) : a+b))) > 0 ? totals[k] : 0, 0)).reduce((x,y) => x+y)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment