diff --git a/2023/README.md b/2023/README.md index caa6ebf..1c20059 100644 --- a/2023/README.md +++ b/2023/README.md @@ -6,10 +6,14 @@ To install dependencies: bun install ``` -To run: +To get the input file: ```bash -bun run index.ts +bun run cli input 1 ``` -This project was created using `bun init` in bun v1.0.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. +To run files: + +```bash +bun run cli run 1 -p 2 +``` \ No newline at end of file diff --git a/2023/src/cli.ts b/2023/src/cli.ts index 6cde16b..8bf2407 100644 --- a/2023/src/cli.ts +++ b/2023/src/cli.ts @@ -1,4 +1,4 @@ -import { readdir } from "fs/promises"; +import { readdir, mkdir } from "fs/promises"; import * as commander from 'commander'; import logger from "./util/logger.ts"; @@ -31,5 +31,14 @@ program await Bun.write(`./src/days/${day}/input.txt`, input); logger('success', `Fetched input for day ${day}`); }); +program + .command('init ') + .description('Initializes a new day') + .action(async (day) => { + await mkdir(`./src/days/${day}`); + await Bun.write(`./src/days/${day}/1.ts`, `import getInput from '../../util/getInput.js';\n\n`); + await Bun.write(`./src/days/${day}/2.ts`, `import getInput from '../../util/getInput.js';\n\n`); + logger('success', `Initialized day ${day}! Happy hacking!`) + }); program.parse(process.argv); \ No newline at end of file diff --git a/2023/src/days/1/2.ts b/2023/src/days/1/2.ts index f9b49d7..301cce2 100644 --- a/2023/src/days/1/2.ts +++ b/2023/src/days/1/2.ts @@ -1,9 +1,6 @@ import getInput from "../../util/getInput.ts" - -// REALLY UNCLEAN CODE BUT IT WORKS const regex = /\D/g const array: Array = [] - let file = await getInput(1) file = file.replaceAll("twone", "21") file = file.replaceAll("sevenine", "79") @@ -23,7 +20,6 @@ file = file.replaceAll("seven", "7") file = file.replaceAll("eight", "8") file = file.replaceAll("nine", "9") const fileSplit = file.split("\n"); - fileSplit.forEach((line) => { let arr = Array.from(line.replace(regex, '')).map(Number) if (arr.length === 0) return diff --git a/2023/src/days/2/1.ts b/2023/src/days/2/1.ts new file mode 100644 index 0000000..b3b4c60 --- /dev/null +++ b/2023/src/days/2/1.ts @@ -0,0 +1,2 @@ +import getInput from '../../util/getInput.js'; + diff --git a/2023/src/days/2/2.ts b/2023/src/days/2/2.ts new file mode 100644 index 0000000..b3b4c60 --- /dev/null +++ b/2023/src/days/2/2.ts @@ -0,0 +1,2 @@ +import getInput from '../../util/getInput.js'; +