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 1cargo test
cargo test --bin 01
cargo test --bin 01 part_one- Install the
rust-analyzerandCodeLLDBextensions - 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 solutioncargo 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 readmeThe --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.sessionfile and paste the πͺ there - Create an
AOC_SESSIONrepo 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
debugmode, integers wrap inreleasemode, leading to wrong output when running your solution.
