forked from vanessayuenn/advent-of-code-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.js
26 lines (23 loc) · 825 Bytes
/
day3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const input = require('./day3-input');
const parse = input
.split('\n')
.map(v => [
+(v.substr(-13, 3).trim())
, +(v.substr(-8, 3).trim())
, +(v.substr(-3).trim())
]);
const isValid = (v => v.length === 3
&& v[0] < v[1] + v[2]
&& v[1] < v[0] + v[2]
&& v[2] < v[0] + v[1])
console.log('--------------- PART 1 ---------------');
const solve1 = parse.filter(isValid);
console.log(`△▽ ${solve1.length} ▽△`);
console.log('--------------- PART 2 ---------------');
let solve2 = 0;
for (let i = 0; i < parse.length; i+=3) {
for (let j = 0; j < 3; j++) {
solve2 += isValid( [parse[i][j], parse[i+1][j], parse[i+2][j]] );
}
}
console.log(`△▽ ${solve2} ▽△`);