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

Day 2 Mark

parent f349081c
No related branches found
No related tags found
No related merge requests found
diff = x => x.map((y,i,l)=>x[i+1]-y).slice(0,-1)
split = x => x.split(" ").map(Number)
bounds1 = x => x >= 1 && x <= 3
bounds2 = x => x >= -3 && x <= -1
isSafe = x => x.every(bounds1) || x.every(bounds2)
output1 = input.split("\n").map(split).map(diff).map(isSafe).reduce((x,y)=>x+y)
dampener = x => isSafe(diff(x)) || x.some((y,z) => isSafe(diff(x.filter((a,b)=>b!=z))))
output2 = input.split("\n").map(split).map(dampener).reduce((x,y)=>x+y)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment