Added day 3

This commit is contained in:
Tim Stallard 2016-12-03 14:55:12 +00:00
parent 491f34a2f7
commit 1ff917bdb9
3 changed files with 1605 additions and 0 deletions

1599
day03/input.txt Normal file

File diff suppressed because it is too large Load Diff

3
day03/part1.js Normal file
View File

@ -0,0 +1,3 @@
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var triangles = input.split("\n").map((a)=>(a.split(" ").filter((b)=>(b)).map((b)=>(parseInt(b))))).filter(([a, b, c])=>(((a + b) > c) && ((b + c) > a) && ((a + c) > b)));
console.log(triangles.length);

3
day03/part2.js Normal file
View File

@ -0,0 +1,3 @@
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);