diff --git a/script/newDay.ts b/script/newDay.ts new file mode 100644 index 0000000..d02f453 --- /dev/null +++ b/script/newDay.ts @@ -0,0 +1,34 @@ +import { promises as fs } from "fs"; +import path from "path"; + +const createNewDay = async (day: number) => { + const dayString = day.toString().padStart(2, "0"); + const inputPath = `./inputs/${dayString}.txt`; + const solutionPath = `./src/${dayString}.ts`; + const testPath = `./test/${dayString}.test.ts`; + + const templateDayPath = path.resolve(__dirname, "./template/day.txt"); + const templateDayContent = await fs.readFile(templateDayPath, "utf-8"); + await fs.writeFile(solutionPath, templateDayContent); + + const templateTestPath = path.resolve(__dirname, "./template/test.txt"); + const templateTestContent = await fs.readFile(templateTestPath, "utf-8"); + const updatedTestContent = templateTestContent.replace(/{{day}}/g, dayString); + await fs.writeFile(testPath, updatedTestContent); + + await fs.writeFile(inputPath, ""); +}; + +const dayArg = process.argv[2]; +if (!dayArg) { + console.error("Please provide a day number as an argument."); + process.exit(1); +} + +const day = parseInt(dayArg, 10); +if (isNaN(day) || day < 1 || day > 25) { + console.error("Please provide a valid day number between 1 and 25."); + process.exit(1); +} + +createNewDay(day); diff --git a/script/template/day.txt b/script/template/day.txt new file mode 100644 index 0000000..b20a4fb --- /dev/null +++ b/script/template/day.txt @@ -0,0 +1,13 @@ +function solution(input: string): { part1: string; part2: string } { + let result1 = 0; + let result2 = 0; + + const lines = input.split("\n"); + + return { + part1: result1.toString(), + part2: result2.toString(), + }; +} + +export default solution; diff --git a/script/template/test.txt b/script/template/test.txt new file mode 100644 index 0000000..170acc4 --- /dev/null +++ b/script/template/test.txt @@ -0,0 +1,20 @@ +import { expect, test, describe } from "bun:test"; +import solution from "../src/{{day}}"; + +const EXAMPLE_1 = `1 2 3 4`; +const RESULT_1 = "2"; + +const EXAMPLE_2 = EXAMPLE_1; +const RESULT_2 = "31"; + +describe("Day 2", () => { + test("Part 1", () => { + const result = solution(EXAMPLE_1); + expect(result.part1).toBe(RESULT_1); + }); + + test.skip("Part 2", () => { + const result = solution(EXAMPLE_2); + expect(result.part2).toBe(RESULT_2); + }); +});