This repository contains TypeScript solutions for Advent of Code puzzles, powered by Bun.
After lack of time and laziness, this project is heavily using AI (gemini pro and copilot). Most of the solutions (body of part 1 and part 2 functions) are generated by AI, with some human tweaking when necessary.
What is done manually:
- Writting the parse function to convert the input string into usable data structures that make sense for the problem.
- Copy/pasting the problem (Part 1 and Part 2) and input into Copilot to get the
solution code, cursor on body of
p1orp2function. - Fix type errors.
- Check the example result is correct, if not, try to fix it or regenerate the code.
- Submit solution on the AoC website.
- Ask gemini pro:
@README.md add the benchmark for day 5(instructions are already in the README.md as a comment). br all(check code, upgrade deps, lint) and commit.
- Bun runtime.
-
Install dependencies:
bun install
-
Configure your session cookie: To automatically fetch puzzle inputs, you need your AoC session cookie.
- Get your
sessioncookie from adventofcode.com (inspect your browser's cookies). - Option A: Set the
AOC_SESSIONenvironment variable. - Option B: Create a file named
.cache/session(create the.cachefolder if it doesn't exist) and paste your session string into it.
Note: The
.cachedirectory is included in.gitignoreto keep your session data private. - Get your
To run a specific day's solution. If the file does not exist, it will be automatically created from a template.
bun start aoc_YYYY_DDExample:
bun start aoc_2025_01What this does:
- Checks if
aoc_2025_01.tsexists. - If it doesn't exist:
- Creates the file using a standard template.
- Fetches the puzzle input from adventofcode.com (using your session cookie)
and saves it to
.cache/.
- Runs the exported functions:
p1ex(Part 1 Example),p1(Part 1),p2ex(Part 2 Example), andp2(Part 2). - Runs benchmarks for
p1andp2.
The package.json includes several helper scripts:
bun start <filename_without_extension>: Runs the specified solution file in watch mode.bun run check: Runs formatting and linting checks usingdeno fmt,oxlint, andbiome.bun run lint: Runs the TypeScript compiler check (tsc --noEmit).bun run upgrade: Updates dependencies to the latest versions.bun run all: Runs upgrade, check, and lint in sequence.
index.ts: The main entry point that handles loading solution files, running functions, and benchmarking.session.ts: Manages fetching and caching of puzzle inputs.aoc_YYYY_DD.ts: Solution files for Advent of Code.apug_YYYY_DD.ts: Solutions for APUG puzzles..cache/: Directory for storing session cookies and cached puzzle inputs.
- Automatic Template Generation: Start working immediately by running the command for a new day.
- Input Caching: Respects AoC servers by caching inputs locally.
- Built-in Benchmarking: Uses
mitatato benchmark your solutions automatically. - Hybrid Performance Comparison: Some solutions (e.g.,
aoc_2025_02) include optimized C implementations viabun:ffi. These are automatically benchmarked alongside the TypeScript versions (p1_cvsp1). - Type Safety: Uses
zodfor input parsing validation.
This project is open source.
Benchmarks are run on a AMD Ryzen 9 270 w/ Radeon 780M Graphics. Runtime: bun 1.3.3 (x64-linux)
| Day | Part 1 | Part 2 | |
|---|---|---|---|
| ⭐️⭐️ | Day 1: Secret Entrance | 0.025ms | 0.020ms |
| ⭐️⭐️ | Day 2: Gift Shop | 0.002ms | 0.042ms |
| ⭐️⭐️ | Day 3: Lobby | 0.039ms | 0.507ms |
| ⭐️⭐️ | Day 4: Printing Department | 0.53ms | 0.83ms |
| ⭐️⭐️ | Day 5: Cafeteria | 0.566ms | 0.019ms |
| ⭐️⭐️ | Day 6: Trash Compactor | 0.011ms | 0.010ms |
| ⭐️⭐️ | Day 7: Laboratories | 0.016ms | 0.038ms |
| ⭐️⭐️ | Day 8: Playground | 4.56ms | 3.05ms |
| ⭐️⭐️ | Day 9: Movie Theater | 0.385ms | 2.11ms |
| ⭐️⭐️ | Day 10: Factory | 6.66ms | 28.15ms |
| ⭐️⭐️ | Day 11: Reactor | 0.009ms | 0.428ms |
| ⭐️⭐️ | Day 12: Christmas Tree Farm | 162390ms | 24stars |