advent-of-code/2022/day1.ts

20 lines
537 B
TypeScript
Raw Normal View History

2022-12-01 10:15:31 -06:00
const tDec = new TextDecoder();
const input = tDec.decode(Deno.readFileSync("day1.input"));
console.log(
"final",
input.split("\n\n").map((p) => {
const ns = p.split("\n").map((s) => {
const n = parseInt(s, 10);
console.log("inner", s, n);
return n;
}).filter((n) => !isNaN(n));
if (ns.length < 1) return NaN;
const n = ns.reduce((prev, cur) => prev + cur, 0);
console.log("oter", p, n, ns);
return n;
}).filter((n) => !isNaN(n)).sort().reverse(),
);
console.log(71924 + 69893 + 68589);