/advent-of-code-2020

:christmas_tree: My Advent of Code solutions in Rust. http://adventofcode.com/2020

Primary LanguageRustGNU General Public License v3.0GPL-3.0

Advent of Code 2020 in Rust

My Advent of Code 2020 solutions in the Rust programming language. This repository holds a separate Rust project for each day and part.

This year I attempt to develop a standalone, short, compact and fast solution for each problem (day part).

I've written an article about my solutions here: https://timvisee.com/blog/solving-aoc-2020-in-under-a-second/

Timings

Here is how long each solution takes to run to completion. All solutions are measured (non scientifically) with hyperfine on a i5-4670k @ 3.8Ghz machine running Linux. Timings include binary loading, execution, input and output timings.

Benchmark

part A part B
day 1 0.170ms 0.007ms
day 2 0.553ms 0.069ms
day 3 0.009ms 0.013ms
day 4 0.157ms 0.185ms
day 5 0.004ms 0.011ms
day 6 0.031ms 0.056ms
day 7 0.002ms 1.71 ms
day 8 0.022ms 0.131ms
day 9 0.043ms 0.025ms
day 10 0.004ms 0.005ms
day 11 0.007ms 6.56 ms
day 12 0.011ms 0.011ms
day 13 0.002ms 0.004ms
day 14 0.276ms 6.10 ms
day 15 0.227ms 511 ms
day 16 0.209ms 0.526ms
day 17 0.357ms 7.98 ms
day 18 0.246ms 0.228ms
day 19 0.364ms 0.523ms
day 20 0.111ms 0.460ms
day 21 0.464ms 0.293ms
day 22 0.003ms 3.42 ms
day 23 0.005ms 192 ms
day 24 0.105ms 43.2 ms
day 25 27.9 ms
one-by-one parallel
everything 699ms 511ms

Run solutions

Each Rust project contains a input.txt file, holding the puzzle input. Simply run the project to see the solution appear.

# One solution requires large stack size, set to allow unlimited size
ulimit -s unlimited

# Switch to day 1a, and run it
cd day01a
cargo run --release

# Or run everything in parallel
cd ../runner
cargo run --release --bin runner-par

# Or benchmark every day
cd ../runner
cargo run --release --bin bench

Some solutions might require Rust Nightly.

Other years

License

This project is released under the GNU GPL-3.0 license. Check out the LICENSE file for more information.