Skip to content

chneau/adventofcode-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

124 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code TypeScript

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 p1 or p2 function.
  • 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.

Prerequisites

Setup

  1. Install dependencies:

    bun install
  2. Configure your session cookie: To automatically fetch puzzle inputs, you need your AoC session cookie.

    • Get your session cookie from adventofcode.com (inspect your browser's cookies).
    • Option A: Set the AOC_SESSION environment variable.
    • Option B: Create a file named .cache/session (create the .cache folder if it doesn't exist) and paste your session string into it.

    Note: The .cache directory is included in .gitignore to keep your session data private.

Usage

Run a Solution

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_DD

Example:

bun start aoc_2025_01

What this does:

  1. Checks if aoc_2025_01.ts exists.
  2. 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/.
  3. Runs the exported functions: p1ex (Part 1 Example), p1 (Part 1), p2ex (Part 2 Example), and p2 (Part 2).
  4. Runs benchmarks for p1 and p2.

Scripts

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 using deno fmt, oxlint, and biome.
  • 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.

Project Structure

  • 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.

Features

  • 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 mitata to benchmark your solutions automatically.
  • Hybrid Performance Comparison: Some solutions (e.g., aoc_2025_02) include optimized C implementations via bun:ffi. These are automatically benchmarked alongside the TypeScript versions (p1_c vs p1).
  • Type Safety: Uses zod for input parsing validation.

License

This project is open source.

Benchmarks

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors