This commit is contained in:
2020-12-09 14:41:45 +00:00
parent 7f2b425726
commit 208377019e
3 changed files with 1058 additions and 0 deletions

23
09/part1.js Normal file
View File

@@ -0,0 +1,23 @@
const fs = require('fs');
const PREAMBLE_SIZE = 25;
fs.readFile('input', (err, data) => {
if (err) throw err;
let input = data.toString().trim().split("\n").map((line) => Number(line) );
let buf = input.slice(0, PREAMBLE_SIZE);
for(pos=PREAMBLE_SIZE;pos<input.length;pos++) {
let next = input[pos];
let sums = new Set( );
buf.forEach((a) => buf.forEach((b) => { if (a != b) sums.add(a+b); }));
if (!sums.has(next)) {
console.log(next);
break;
}
buf = buf.slice(1, 25);
buf.push(next);
}
});