2024-12-01 14:10:32 -07:00
|
|
|
export async function solve() {
|
2024-12-03 21:42:57 -07:00
|
|
|
return await Deno.readTextFile(import.meta.dirname + "/input.txt").then(
|
2024-12-01 14:10:32 -07:00
|
|
|
(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),
|
|
|
|
);
|
|
|
|
}
|