2018 d1 p2

This commit is contained in:
Tristan 2018-12-01 14:12:01 +00:00
parent f6de8ec0a6
commit 75bfcd3838
2 changed files with 22 additions and 2 deletions

View file

@ -957,4 +957,3 @@
-18 -18
-7 -7
+127054 +127054

21
2018/1/part2.js Normal file
View file

@ -0,0 +1,21 @@
const fs = require('fs');
let input = fs.readFileSync('input.txt', 'utf-8');
let freq = 0;
let history = [0];
found = false;
while (!found) {
for (let line of input.split('\n')) {
num = parseInt(line);
if (num) {
freq += num;
}
if (history.includes(freq)) {
found = true;
break;
} else {
history.push(freq);
}
}
}
console.log(freq)