diff --git a/day5/Boarding.ts b/day5/Boarding.ts index 9ccde90..e5486b2 100644 --- a/day5/Boarding.ts +++ b/day5/Boarding.ts @@ -15,13 +15,13 @@ const main = () => { console.log(Math.max(...ids)); ids.sort((a, b) => a - b); const myId = ids.reduce( - (carry, _, currIdx, all) => - carry !== 0 + (carry: number | null, _, currIdx, all) => + carry !== null ? carry : all[currIdx + 1] - all[currIdx] > 1 ? all[currIdx] + 1 : carry, - 0 + null ); console.log(myId); }; diff --git a/day9/XmasCracker.ts b/day9/XmasCracker.ts index 755acaf..1a5d174 100644 --- a/day9/XmasCracker.ts +++ b/day9/XmasCracker.ts @@ -1,4 +1,4 @@ -import { readFileSync } from 'fs'; +// import { readFileSync } from 'fs'; const isValidInSequence = ( sequence: Array, @@ -27,6 +27,7 @@ const findCorruptedNumber = ( }; const findSumSequence = (originalSequence: Array, preamble: number) => { + //Huh. I was lucky this worked. const corruptNumber = findCorruptedNumber(originalSequence, preamble); let start = 0; let end = 0; @@ -44,12 +45,20 @@ const findSumSequence = (originalSequence: Array, preamble: number) => { return originalSequence.slice(start, end); }; -const data = readFileSync('input.txt', 'utf-8') - .split('\n') - .filter((x) => x) - .map((n) => Number.parseInt(n, 10)); +const foo = async () => { + const data = await Deno.readTextFile('input.txt').then((f) => + f + .split('\n') + .filter((x) => x) + .map((n) => Number.parseInt(n, 10)) + ); + console.log(findCorruptedNumber(data, 25)); + const part2 = findSumSequence(data, 25).sort((a, b) => a - b); + console.log(part2[0] + part2[part2.length - 1]); +}; + +foo(); -console.log(findCorruptedNumber(data, 25)); // const testData = [ // 35, // 20, @@ -72,6 +81,4 @@ console.log(findCorruptedNumber(data, 25)); // 309, // 576, // ]; -const part2 = findSumSequence(data, 25).sort((a, b) => a - b); -console.log(part2[0] + part2[part2.length - 1]); // console.log(findSumSequence(testData, 5));