mirror of
https://github.com/SrIzan10/adventofcode.git
synced 2026-06-06 00:46:56 +00:00
chore: implement init on cli and init day 2
This commit is contained in:
@@ -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
|
||||
```
|
||||
@@ -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 <day>')
|
||||
.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);
|
||||
@@ -1,9 +1,6 @@
|
||||
import getInput from "../../util/getInput.ts"
|
||||
|
||||
// REALLY UNCLEAN CODE BUT IT WORKS
|
||||
const regex = /\D/g
|
||||
const array: Array<number> = []
|
||||
|
||||
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
|
||||
|
||||
2
2023/src/days/2/1.ts
Normal file
2
2023/src/days/2/1.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import getInput from '../../util/getInput.js';
|
||||
|
||||
2
2023/src/days/2/2.ts
Normal file
2
2023/src/days/2/2.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import getInput from '../../util/getInput.js';
|
||||
|
||||
Reference in New Issue
Block a user