This is a template for solving Advent of Code puzzles in Rust.
It's structured as a single Cargo crate with a library and a binary.
src/lib.rs: Contains the main solve function that dispatches to the correct day's module. It also declares all day modules.src/main.rs: A simple command-line runner that parses args (day, part) and calls solve.src/common.rs: For any shared helper functions (like reading input).src/dayXX.rs: Each day gets its own module file.input/: This directory holds your puzzle inputs.tasks/: This directory holds your puzzle description
Table for README for each task and if the task is completed
| DAY | TASK 1 | TASK 2 |
|---|---|---|
| day 1 | ✓ | ✓ |
| day 2 | ✓ | ✓ |
| day 3 | ✓ | ✓ |
| day 4 | ✓ | ✓ |
| day 5 | ✓ | ✓ |
| day 6 | ✓ | |
| day 7 | ✓ | ✓ |
| day 8 | ✓ | |
| day 9 | ✓ | ✓ |
| day 10 | ✓ | ✓ |
| day 11 | ✓ | ✓ |
| day 12 | ✓ | ✓ |
| day 13 | ✓ | ✓ |
| day 14 | ||
| day 15 | ||
| day 16 | ||
| day 17 | ||
| day 18 | ||
| day 19 | ||
| day 20 | ||
| day 21 | ||
| day 22 | ||
| day 23 | ||
| day 24 | ||
| day 25 |
- Add a New Day:
- Create
src/dayDD.rs(you can copysrc/dayXY.rsas a template). - Create
input/DD.txt-> INPUT - Create
input/DD_sample.txt-> SAMPLE - In
src/lib.rs:- Add
pub mod dayDD; - Add a new arm to the
match dayexpression in thesolvefunction:
- Add
DD => match part {
1 => dayDD::part1(input).to_string(),
2 => dayDD::part2(input).to_string(),
_ => "Invalid part".to_string(),
},
- Implement tests and solution in
src/dayDD.rs.
- Run a Solution:
- The
cargo runcommand requires--to separate Cargo's arguments from your program's arguments.- fe.: run Day 1, Part 1 -> with input:
cargo run -- 1 1
- fe.: run Day 1, Part 2 with sample:
cargo run -- 1 2 --sample
- Run Tests:
- Run all tests:
cargo test - Run tests for a specific day:
cargo test --package aoc_2024 --lib day01
- on the page Select:
View page Source - Save the code between:
<article> ... </article>into aday.html - Run:
python TRANSFORM.py - TaDa there will occur output in the console output and file:
day.md