Skip to content

nindalf/advent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code

This repo has my solutions to Advent of Code, written in Rust.

I've tried to write idiomatic, readable code. I attempt to make my code fast, but if it's a choice between fast and readable, I choose readable. No unsafe code or SIMD here.

That said, the code is pretty fast. My solutions for 2024 run in 84ms total. I've written in detail about the optimisations I've used to make my solutions faster - Optimising my Rust solutions for Advent of Code. These tips are general and could be applied to most Rust programs.

Benchmarks

Successfully completed problems with the time taken to execute them on my M1 Pro.

2024

Day Problem Solution Part 1 (ms) Part 2 (ms) Total (ms)
1 Historian Hysteria Solution 0.04 0.04 0.08
2 Red-Nosed Reports Solution 0.08 0.09 0.18
3 Mull It Over Solution 0.22 0.22 0.44
4 Ceres Search Solution 0.14 0.09 0.23
5 Print Queue Solution 0.16 0.16 0.31
6 Guard Gallivant Solution 0.08 2.55 2.63
7 Bridge Repair Solution 0.18 5.02 5.20
8 Resonant Collinearity Solution 0.02 0.04 0.06
9 Disk Fragmenter Solution 0.24 0.61 0.84
10 Hoof It Solution 0.08 0.05 0.13
11 Plutonian Pebbles Solution 0.04 2.61 2.65
12 Garden Groups Solution 1.09 1.94 3.03
13 Claw Contraption Solution 0.03 0.03 0.07
14 Restroom Redoubt Solution 0.04 0.19 0.23
15 Warehouse Woes Solution 0.43 0.58 1.00
16 Reindeer Maze Solution 3.01 6.38 9.39
17 Chronospatial Computer Solution 0.00 5.35 5.35
18 RAM Run Solution 0.27 1.15 1.42
19 Linen Layout Solution 0.33 0.34 0.67
20 Race Condition Solution 0.52 4.64 5.16
21 Keypad Conundrum Solution 0.01 0.06 0.07
22 Monkey Market Solution 1.29 34.22 35.51
23 LAN Party Solution 0.37 7.92 8.28
24 Crossed Wires Solution 0.03 0.05 0.07
25 Code Chronicle Solution 0.16 0.00 0.16
Total 8.86ms 74.33ms 83.19ms

Setup

  1. Clone this repo - gh repo clone nindalf/advent or git clone [email protected]:nindalf/advent.git.
  2. Install Rust or update - rustup update.
  3. Install just, the command runner.
  4. Install aocgen, which fetches the problem input and creates the empty files.

How to use

Run just for all the available commands.

By default just will run these for the latest year, set by the env variable AOC_YEAR.

just fetch 15         # fetches the 15th day's problem and input.

just test 15 1_t      # runs day15::tests::part1_test
just test 15 1_r      # runs day15::tests::part1_real
just test 15 1        # runs both tests for day 15 part 1
just test 15 2        # runs both tests for day 15 part 2
just test 15          # runs all 4 tests for day 15

just submit 15 1 1024 # Submit "1024" as the solution for Day 15 Part 1
just submit 15 2 2048 # Submit "2048" as the solution for Day 15 Part 2

just bench 15         # benchmarks day 15 parts 1 and 2

just test/just bench with no arguments runs all the tests/benchmarks for the latest year.

Overriding AOC_YEAR

If AOC_YEAR is not set, it picks up the default from the justfile. To run the commands for a different year, you can choose one of these options:

  • Set it permanently
    • Set the env variable - export AOC_YEAR=2023
    • Change the default in the justfile - AOC_YEAR := env_var_or_default("AOC_YEAR", "2023")
  • Set it for one invocation
    • AOC_YEAR=2023 just test OR
    • just --set AOC_YEAR 2023 test

About

My solutions to Advent of Code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published