commit f33dda8916d4370686f76ba5c07347a7c558b7042a2e326e0208befbfa7842df Author: Leonard Lorenz Date: Tue Dec 2 22:20:36 2025 +0100 ₍^. .^₎⟆ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85b002b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +.session +.tool_versions +input \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..182051d --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +deno 2.5.6 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9bd3a4a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "request": "launch", + "name": "Launch Program", + "type": "node", + "program": "${workspaceFolder}/main.ts", + "cwd": "${workspaceFolder}", + "env": {}, + "runtimeExecutable": "/Users/mtrx/.asdf/shims/deno", + "runtimeArgs": [ + "run", + "--unstable", + "--inspect-wait", + "--allow-all" + ], + "attachSimplePort": 9229 + } + ] +} \ No newline at end of file diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..d1f5ffb --- /dev/null +++ b/deno.json @@ -0,0 +1,8 @@ +{ + "tasks": { + "dev": "deno run --watch --allow-read=. main.ts" + }, + "imports": { + "@std/assert": "jsr:@std/assert@1" + } +} diff --git a/load-todays-input.bash b/load-todays-input.bash new file mode 100644 index 0000000..3468018 --- /dev/null +++ b/load-todays-input.bash @@ -0,0 +1,5 @@ +day=$(date +%-e) +day_zero=$(date +%0e) +session=$(cat .sessioncookie) +mkdir -p input +curl -b "session=${session}" -o "./input/${day_zero}.txt" "https://adventofcode.com/2024/day/${day}/input" \ No newline at end of file diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..523ac96 --- /dev/null +++ b/main.ts @@ -0,0 +1,22 @@ +import type { Solvable } from "./solvable.ts"; + +const solutionFiles = Deno.readDirSync('./solutions'); + +const solvables: Solvable[] = []; + +// need to wrap this stuff in a function to not trip the top level await +(async () => { + // cool dynamic module loading + for (const solution of solutionFiles) { + await import('./solutions/' + solution.name) + } + + // only solve the latest day + console.log("Solving latest day only:") + const day = solvables.toReversed()[0]; + day.part1() + day.part2() +})() + + +export { solvables } \ No newline at end of file diff --git a/solutions/01.ts b/solutions/01.ts new file mode 100644 index 0000000..13e20eb --- /dev/null +++ b/solutions/01.ts @@ -0,0 +1,59 @@ +import { solvables } from "../main.ts"; + +import type { Solvable } from "../solvable.ts"; +import { readInput } from "../utils.ts"; + +class DayOne implements Solvable { + input = readInput('01') + + public part1(): DayOne { + const vals: [string, number][] = this.input + .split("\n") + .map(line => [line[0], Number.parseInt(line.slice(1))]); + + let state = 50; + let zerooccurences = 0; + for (const [direction, amount] of vals) { + if (direction === 'R') { + state += amount % 100; + state %= 100; + } else if (direction === 'L') { + state -= amount % 100; + if (state < 0) state += 100; + } + state === 0 ? zerooccurences++ : null; + } + console.log(zerooccurences) + return this + } + + public part2(): DayOne { + const vals: [string, number][] = this.input + .split("\n") + .map(line => [line[0], Number.parseInt(line.slice(1))]); + let state = 50; + let zerooccurences = 0; + + for (const [direction, amount] of vals) { + for (let i = 0; i < amount; i++) { + state === 0 ? zerooccurences++ : null; + if (direction === 'R') { + state += 1; + if (state === 100) { + state = 0; + } + } else if (direction === 'L') { + state -= 1; + if (state === -1) { + state = 99; + } + } + } + } + + console.log(zerooccurences) + return this + } +} + +solvables.push(new DayOne()) \ No newline at end of file diff --git a/solutions/02.ts b/solutions/02.ts new file mode 100644 index 0000000..e4d8be3 --- /dev/null +++ b/solutions/02.ts @@ -0,0 +1,22 @@ +import { solvables } from "../main.ts"; + +import type { Solvable } from "../solvable.ts"; +import { readInput } from "../utils.ts"; + +class DayOne implements Solvable { + input = readInput('01') + + public part1(): DayOne { + const vals: [string, number][] = this.input + .split("\n") + .map(line => [line[0], Number.parseInt(line.slice(1))]); + + return this + } + + public part2(): DayOne { + return this + } +} + +solvables.push(new DayOne()) \ No newline at end of file diff --git a/solvable.ts b/solvable.ts new file mode 100644 index 0000000..413dcf0 --- /dev/null +++ b/solvable.ts @@ -0,0 +1,6 @@ +interface Solvable { + part1(): Solvable; + part2(): Solvable; +} + +export type { Solvable } \ No newline at end of file diff --git a/utils.ts b/utils.ts new file mode 100644 index 0000000..5a39944 --- /dev/null +++ b/utils.ts @@ -0,0 +1,7 @@ +function readInput(day: string): string { + return Deno.readTextFileSync('./input/' + day + '.txt').trim() +} + +const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); + +export { readInput, delay };