adventofcode-2016/day03/part2.js
2016-12-03 14:55:12 +00:00

4 lines
380 B
JavaScript

var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var triangles = input.replace(/\n/g, " ").split(" ").filter((a)=>(a)).map((a)=>(parseInt(a))).reduce((a, b, i)=>{x = Math.floor(i/9)*3 + i%3; if(!a[x]){a[x] = []}; a[x].push(b); return a;}, []).filter(([a, b, c])=>(((a + b) > c) && ((b + c) > a) && ((a + c) > b)));
console.log(triangles.length);