Added day 3
This commit is contained in:
parent
491f34a2f7
commit
1ff917bdb9
1599
day03/input.txt
Normal file
1599
day03/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
day03/part1.js
Normal file
3
day03/part1.js
Normal 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
3
day03/part2.js
Normal 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);
|
Loading…
Reference in New Issue
Block a user