diff --git a/2023/base/deno.json b/2023/base/deno.json index 5881ebc..eb7be8f 100644 --- a/2023/base/deno.json +++ b/2023/base/deno.json @@ -1,5 +1,8 @@ { "tasks": { + "cache": "deno cache part1.ts part2.ts", + "pull": "aoc --day 1 download --overwrite", + "test": "deno test --watch", "p1": "deno run -A part1.ts", "p2": "deno run -A part2.ts" } diff --git a/2023/base/part1.ts b/2023/base/part1.ts index 94d9dc3..5658bc9 100644 --- a/2023/base/part1.ts +++ b/2023/base/part1.ts @@ -1,4 +1,13 @@ -const input = await Deno.readFile("input").then((bytes) => - new TextDecoder().decode(bytes), -); -const lines = input.trim().split("\n"); +if (import.meta.main) { + const input = ( + await Deno.readFile("input").then((bytes) => + new TextDecoder().decode(bytes), + ) + ).trim(); + console.log(answer(input)); +} + +export function answer(input: string): number { + console.log(input); + return 42; +} diff --git a/2023/base/part2.ts b/2023/base/part2.ts new file mode 100644 index 0000000..5658bc9 --- /dev/null +++ b/2023/base/part2.ts @@ -0,0 +1,13 @@ +if (import.meta.main) { + const input = ( + await Deno.readFile("input").then((bytes) => + new TextDecoder().decode(bytes), + ) + ).trim(); + console.log(answer(input)); +} + +export function answer(input: string): number { + console.log(input); + return 42; +} diff --git a/2023/base/test.ts b/2023/base/test.ts new file mode 100644 index 0000000..ef5e047 --- /dev/null +++ b/2023/base/test.ts @@ -0,0 +1,13 @@ +import { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts"; +import * as p1 from "./part1.ts"; +import * as p2 from "./part2.ts"; + +Deno.test("part1", () => { + const examples = ["abc", "def"].join("\n"); + assertEquals(p1.answer(examples), 42); +}); + +Deno.test("part2", () => { + const examples = ["abc", "def"].join("\n"); + assertEquals(p2.answer(examples), 42); +});