Solutions for Advent of Code in Rust.
Day | Part 1 | Part 2 |
---|---|---|
Day 1 | โญ | โญ |
Day 2 | โญ | โญ |
Day 3 | โญ | โญ |
Day 4 | โญ | โญ |
Day 5 | โญ | โญ |
Day 6 | โญ | โญ |
Day 7 | โญ | โญ |
cargo scaffold 1 --download # Create scaffolding for day 1 and download puzzle input
cargo scaffold 1 # Create scaffolding for day 1
cargo download 1 # Download puzzle input for day 1
cargo read 1 # Read puzzle description for day 1
cargo test
cargo test --bin 01
cargo test --bin 01 part_one
- Install the
rust-analyzer
andCodeLLDB
extensions - Set breakpoints in your code
- Click Debug next to the unit test or the main function
- The debugger will halt your program at the specific line and allow you to inspect the local stack
cargo solve 1 # Run day 1 solution against real puzzle inputs
cargo solve 1 2 # Run day 1, part 2 solution against real puzzle inputs
cargo solve 1 2 --release # Run day 1, part 2 solution against real puzzle inputs with an optimized build
cargo all # Run all solutions sequentially
cargo all --release # Run all solutions sequentially with optimized build
cargo solve 1 --submit 2 # Submit day 1, part 2 solution
cargo time 1 # Run day 1 10-10K times (depending on execution time) and print the average runtime
cargo time --all # Print the average runtime for all days
cargo solve 1 --dhat # Analyze day 1 heap allocations with DHAT (https://valgrind.org/docs/manual/dh-manual.html)
cargo time 1 --store # Add day 1 timings to the readme
cargo time --all --store # Add all timings to the readme
The --dhat
command will output some basic stats to the command-line and generate a dhat-heap.json
report in the repo root directory. You can pass the report a tool like dh-view to view a detailed breakdown of heap allocations.
cargo fmt
cargo clippy
- Copy the
session
๐ช from the AOC website (you'll find it under Cookies in the Application or Storage tab) - Create a
$HOME/.adventofcode.session
file and paste the ๐ช there - Create an
AOC_SESSION
repo secret and paste the ๐ช there as well (Settings -> Secrets -> New repository secret) - When the ๐ช expires, repeat steps 1-3, replacing the old value with the new one
- Whitespace in input: Make sure the input file has no leading or trailing whitespace, including no newline at the end of the file.
- Integer overflows: This template uses 32-bit integers by default because it is generally faster - for example when packed in large arrays or structs - than using 64-bit integers everywhere. For some problems, solutions for real input might exceed 32-bit integer space. While this is checked and panics in
debug
mode, integers wrap inrelease
mode, leading to wrong output when running your solution.