Skip to content

🎄 My solutions to Advent of Code (in Rust 🦀)

License

Notifications You must be signed in to change notification settings

michel-kraemer/adventofcode-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

534 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code

These are my solutions to the annual Advent of Code challenge.

Goals

🦀 Implement everything in Rust

👍 Find generalized solutions that work with every input

⛓️‍💥 Avoid 3rd party dependencies (if possible and reasonable). Exceptions are rustc-hash (because it's just too fast), rayon for parallelization (only in rare cases!), and any crate necessary to do occasional terminal visualizations.

🏃‍♂️‍➡️ Try to optimize performance (to the best of my knowledge and if it doesn't conflict with the other goals). See benchmarks below.

🤓 Find clever solutions to complex problems that others might not have found. Some highlights I'm particularly proud of:

  • Day 10 of 2025: While most people approached this problem using a solver (such as S3 or good_lp), I found a solution that works completely without a 3rd party dependency. I implemented a DFS in which I use heuristics to prune as many branches as possible. This is definitely not the fastest approach possible, but it gets the job done in reasonable time and is certainly quite unique. See my Reddit comment for more information.
  • Day 25 of 2023: Using Brandes' algorithm to quickly calculate the betweenness centrality of graph nodes.
  • Day 21 of 2023: Applying bit operations to simulate the cellular automaton, which allowed me to implement a fast and generalized solution that should work on any input (unlike most other approaches).
  • Day 25 of 2018: Combining DBSCAN with a spatial index based on Morton indices. Very fast and scalable!
  • Day 25 of 2017: Fast Turing machine simulation using memoized macro transitions over fixed-size blocks inspired by tape compression and the linear speedup theorem.

Terminal visualizations

I've created terminal visualizations of some puzzles for fun:


2025 - Day 12:
Christmas Tree Farm

2025 - Day 4:
Printing Department

2024 - Day 15:
Warehouse Woes

2019 - Day 13:
Care Package

2018 - Day 18:
Settlers of The North Pole

2017 - Day 22:
Sporifica Virus

2016 - Day 22:
Grid Computing

2016 - Day 8:
Two-Factor Authentication

2015 - Day 18:
Like a GIF For Your Yard

If you want to visualize your own input with my code, just change into the solution's directory (e.g. cd 2025/day12) and run the following command:

AOC_VISUALIZE=true cargo run --release

Benchmarks

All measurements were performed with my cargo bench-aoc tool on a MacBook Pro 16″ 2023 with an Apple M3 Pro processor. The tool uses Divan under the hood to provide accurate and reproducible benchmark results. I/O (reading input files and printing answers to the terminal) is NOT included in the measurements.

2018

Day 1:23µs Day 2:29µs Day 3:605µs Day 4:42µs Day 5:426µs
Day 6:205µs Day 7:3µs Day 8:28µs Day 9:... Day 10:15µs
Day 11:2ms Day 12:13µs Day 13:294µs Day 14:110ms Day 15:...
Day 16:22µs Day 17:75µs Day 18:2ms Day 19:4µs Day 20:2ms
Day 21:118µs Day 22:6ms Day 23:447µs Day 24:... Day 25:341µs

2017

Day 1:2µs Day 2:3µs Day 3:749ns Day 4:196µs Day 5:43ms
Day 6:253µs Day 7:117µs Day 8:37µs Day 9:14µs Day 10:35µs
Day 11:37µs Day 12:146µs Day 13:5ms Day 14:2ms Day 15:205ms
Day 16:154µs Day 17:44µs Day 18:291µs Day 19:25µs Day 20:2ms
Day 21:5µs Day 22:41ms Day 23:80µs Day 24:3ms Day 25:2ms

2016

Day 1:2µs Day 2:5µs Day 3:54µs Day 4:55µs Day 5:376ms
Day 6:6µs Day 7:635µs Day 8:6µs Day 9:9µs Day 10:12µs
Day 11:1ms Day 12:21ms Day 13:1µs Day 14:1.6s Day 15:1µs
Day 16:2µs Day 17:14ms Day 18:592µs Day 19:88ns Day 20:37µs
Day 21:7µs Day 22:3ms Day 23:1µs Day 24:137µs Day 25:26µs

2015

Day 1:6µs Day 2:41µs Day 3:73µs Day 4:143ms Day 5:180µs
Day 6:6ms Day 7:23µs Day 8:7µs Day 9:19µs Day 10:16ms
Day 11:8ms Day 12:125µs Day 13:42µs Day 14:23µs Day 15:3ms
Day 16:53µs Day 17:43µs Day 18:116µs Day 19:155µs Day 20:12ms
Day 21:3µs Day 22:185µs Day 23:5µs Day 24:295µs Day 25:180ns

License

The solutions are released under the MIT license. See the LICENSE file for more information.