Skip to content

Commit

Permalink
Play around with using Deno
Browse files Browse the repository at this point in the history
  • Loading branch information
blanky0230 committed Dec 9, 2020
1 parent 63cc65b commit fdc7062
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions day5/Boarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
23 changes: 15 additions & 8 deletions day9/XmasCracker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from 'fs';
// import { readFileSync } from 'fs';

const isValidInSequence = (
sequence: Array<number>,
Expand Down Expand Up @@ -27,6 +27,7 @@ const findCorruptedNumber = (
};

const findSumSequence = (originalSequence: Array<number>, preamble: number) => {
//Huh. I was lucky this worked.
const corruptNumber = findCorruptedNumber(originalSequence, preamble);
let start = 0;
let end = 0;
Expand All @@ -44,12 +45,20 @@ const findSumSequence = (originalSequence: Array<number>, 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,
Expand All @@ -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));

0 comments on commit fdc7062

Please sign in to comment.