advent-of-code-2024/day1/part1.ts

17 lines
549 B
TypeScript
Raw Normal View History

2024-11-30 22:39:43 -07:00
const input = await Deno.readTextFile("./input.txt").then(
(f) =>
f.split("\n").reduce<[number[], number[]]>(
(
acc,
cur,
) => [[...acc[0], +cur.split(" ")[0]], [
...acc[1],
+cur.split(" ")[1],
]],
[[], []],
),
).then(([first, second]) => [first.toSorted(), second.toSorted()]).then((
[first, second],
) => first.reduce((acc, cur, i) => acc + Math.abs(cur - second[i]), 0));
console.log("Answer = " + input);