diff --git a/2018/1/input.txt b/2018/1/input.txt index 8855f9d..444c50b 100644 --- a/2018/1/input.txt +++ b/2018/1/input.txt @@ -956,5 +956,4 @@ -3 -18 -7 -+127054 - ++127054 \ No newline at end of file diff --git a/2018/1/part2.js b/2018/1/part2.js new file mode 100644 index 0000000..5bdf32b --- /dev/null +++ b/2018/1/part2.js @@ -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)