From 58df0a8bbe0951c56ebb15c90bd391458e766b6b Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Wed, 29 Nov 2023 15:57:17 +0100 Subject: [PATCH] add ts --- .nvmrc | 1 + README.md | 53 ++++++++++++++++++++++--- _templates/riddle/new/python.ejs.t | 26 +++++++++--- _templates/riddle/new/typescript.ejs.t | 24 +++++++++++ bun.lockb | Bin 37641 -> 38798 bytes package.json | 7 +++- tsconfig.json | 12 ++++++ 7 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 .nvmrc create mode 100644 _templates/riddle/new/typescript.ejs.t create mode 100644 tsconfig.json 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 568f09a49f0debff6878d3a7d51f9a4f3f8bc364..053d2e42911be03475b52b6372af26121cc9b5cd 100755 GIT binary patch delta 6726 zcmeHMYfw~Iwm$pVJPz6-h(OyA1QkSi2rV>-c7rb?bG&<4X zGn%Cay)kNLbaY~d$q*BrnLNFwBxRDZv}S^d-myq3(L^V&>%^NY_kQaC1S|3rx1 z9~P?5Th`(&p^<-JYI zSNK}IElQLopVIDK>W7#lE%ns1yu>Cp`22yp?$KU3E%+)%SiK#40!{5v;Jj>@!JC$4 zR(t$jsSCD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qSZriHr8U0#Sk12wHgQyH~iidLrNfp z5IP`GzjcgC2c|(hkf{(R9Cg`_%o^d1 z1pim(ztvXo7&HcqftwBC!f-9=G?BrgPdvxYhj7stltmB*?s7;egu!CaDCCRL8rL8pv7*r%?}K$iEEP z3}H?&x2}aSlX#kAR$)oxs+~C_%rXv-#L9&zhL3w45yti|)tm>K*aIf3kn+=@{ZtL3wvq)7;-eE0eG1txrF4 zX2b5EKr2*MQHDhOP?PJseF66p?y=kN-+!z3Kii>zW-8>#k#4^#mdEfLlDdIe@?v)j zK6SyKkh0qf0Q9DiL`w^U#X z$cK9Qs3)Y4d!(|rL+zFE-jIHNs{EqY7jSR%{yy~l#^WbG2s^WabAzJ#IA)+Pq~^({ zKK}~$9&htAZ+Y(d&6~xRZbcc6Z|;p=yydy3t?!(@@TqSJiz8dVcFUEP+D!RmDBpI@?k3H{bDXZ0_N;k`k$Z#s-D%VGn$-7h{=7r8xTV5&0UUUY66Dm`9x{_&43 z`^(C(X|9srr9z9`3(&mbTLO!|`N};`62ic;A!}FAdWWRpE32DrlIZVk-Hi+0b88|$ z_W89{P81?gjrgaBDKVJ@(?e;JM%@c5b=7qrPtLHyxvW lM`gxMi!<7j{R8FOlHGFTZ{|&$yD8?IXuflsj+4b*{|zh+dV>G} 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"] + } +}