2018 d1 p2
This commit is contained in:
parent
f6de8ec0a6
commit
75bfcd3838
|
@ -956,5 +956,4 @@
|
|||
-3
|
||||
-18
|
||||
-7
|
||||
+127054
|
||||
|
||||
+127054
|
21
2018/1/part2.js
Normal file
21
2018/1/part2.js
Normal 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)
|
Loading…
Reference in a new issue