reformat and clean up
This commit is contained in:
parent
3234d984fd
commit
7bdeb7864b
4 changed files with 51 additions and 1039 deletions
9
aoc
Executable file
9
aoc
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env zsh
|
||||
setopt extendedglob
|
||||
|
||||
cd "day$1"
|
||||
|
||||
# Handle deno days
|
||||
if [[ -n *.ts(#qN) ]]; then
|
||||
deno eval --ext=ts "await import('./part$2.ts').then(m => m.solve()).then(s => console.log('The solution is', s))"
|
||||
fi
|
1000
day1/input.txt
1000
day1/input.txt
File diff suppressed because it is too large
Load diff
|
@ -1,16 +1,18 @@
|
|||
const input = await Deno.readTextFile("./input.txt").then(
|
||||
export async function solve() {
|
||||
return 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],
|
||||
]],
|
||||
) => [
|
||||
[...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);
|
||||
).then(([first, second]) => [first.toSorted(), second.toSorted()]).then(
|
||||
([first, second]) =>
|
||||
first.reduce((acc, cur, i) => acc + Math.abs(cur - second[i]), 0),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
const input = await Deno.readTextFile("./input.txt").then(
|
||||
export async function solve() {
|
||||
return 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],
|
||||
]],
|
||||
) => [
|
||||
[...acc[0], +cur.split(" ")[0]],
|
||||
[...acc[1], +cur.split(" ")[1]],
|
||||
],
|
||||
[[], []],
|
||||
),
|
||||
).then(([first, second]) => [
|
||||
).then(([first, second]) => [
|
||||
first,
|
||||
second.reduce((acc, cur) => {
|
||||
if (acc[cur] !== undefined) acc[cur]++;
|
||||
|
@ -18,7 +19,7 @@ const input = await Deno.readTextFile("./input.txt").then(
|
|||
|
||||
return acc;
|
||||
}, {} as Record<number, number>),
|
||||
]).then(([first, map]) =>
|
||||
] as const).then(([first, map]) =>
|
||||
first.reduce((acc, cur) => acc + ((map[cur] ?? 0) * cur), 0)
|
||||
);
|
||||
console.log("Answer = " + input);
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue