diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..1689437 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v21 diff --git a/README.md b/README.md index ef604ef..201a4c4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # Advent Of Code +Template repository for Advent of Code. It automatically downloads your puzzle inputs and bootstraps files for the following languages: + +- Typescript +- Python +- Rust + +Have fun! 🤗🎄 + ## Getting started New "days" are generated with [`hygen`](https://github.com/jondot/hygen). This will bootstrap code for python and rust. See details about the specifica languages below @@ -8,27 +16,60 @@ New "days" are generated with [`hygen`](https://github.com/jondot/hygen). This w # First time setup bun i -# Generate +# Put the Advent of Code token into .env + +# Generate day bun run gen --year 2022 --day 1 ``` -## Python +## Languages -## Rust +Below are instructions for the specific handling of each language included. + +### Typescript Run a single day: ```bash -cargo run --bin 2022-01 +# Once +bun run 2022/01/typescript/main.ts + +# Rerun on change +bun run --watch 2022/01/typescript/main.ts ``` -Bench a day: +### Python + +```bash +# Get a python enabled shell, with the latest version +poetry shell + +# Run once +python 2022/01/python/main.py + +# Rerun on change +bunx nodemon 2022/01/python/main.py +``` + +### Rust + +Run a single day: + +```bash +# Once +cargo run --bin 2022-01 + +# Rerun on change (requires: https://github.com/watchexec/cargo-watch) +cargo watch -x 'run --bin 2022-01' +``` + +Benchmark a day: ```bash cargo bench --bin 2022-01 ``` -Bench all days: +Benchmark all days: ```bash cargo bench diff --git a/_templates/riddle/new/python.ejs.t b/_templates/riddle/new/python.ejs.t index 58ffbd0..30c6745 100644 --- a/_templates/riddle/new/python.ejs.t +++ b/_templates/riddle/new/python.ejs.t @@ -6,9 +6,7 @@ unless_exists: true from os.path import join, dirname -# Day <%= day %> - -# Common +# Setup def read_input(filename): @@ -17,7 +15,25 @@ def read_input(filename): return f.read().strip() -test = read_input('test.txt') -data = read_input('input.txt') +TEST = read_input('test.txt') +INPUT = read_input('input.txt') + +# Task + +def part_a(raw: str): + pass + + +def part_b(raw: str): + pass # Running + +print('1.') +print(part_a(TEST)) +print(part_a(INPUT)) + +print('\n2.') +print('1.') +print(part_b(TEST)) +print(part_b(INPUT)) diff --git a/_templates/riddle/new/typescript.ejs.t b/_templates/riddle/new/typescript.ejs.t new file mode 100644 index 0000000..e467e4c --- /dev/null +++ b/_templates/riddle/new/typescript.ejs.t @@ -0,0 +1,24 @@ +--- +to: <%= dir %>/typescript/main.ts +unless_exists: true +--- +import fs from 'node:fs' +import path from 'node:path' + +// SETUP +const INPUT = fs.readFileSync(path.join(__dirname, '../input.txt'), 'utf-8').trim() +const TEST = fs.readFileSync(path.join(__dirname, '../test.txt'), 'utf-8').trim() + +// TASK + +function partA(input: string) {} + +function partB(input: string) {} + +console.log('Part A:') +partA(TEST) +partA(INPUT) + +console.log('Part B:') +partA(TEST) +partB(INPUT) diff --git a/bun.lockb b/bun.lockb index 568f09a..053d2e4 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index a4d817a..02f44ce 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,14 @@ { + "name": "advent-of-code", + "type": "module", "scripts": { "gen": "bun hygen riddle new" }, "dependencies": { + "@tsconfig/strictest": "^2.0.2", "axios": "^1.6.0", - "hygen": "^6.2.11" + "bun-types": "latest", + "hygen": "^6.2.11", + "typescript": "^5.0.0" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d3d9611 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": ["@tsconfig/strictest"], + "compilerOptions": { + "lib": ["ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "noEmit": true, + "types": ["bun-types"] + } +}