/advent-of-code-rust

Advent of Code solutions in Rust by TBali

Primary LanguageRustMIT LicenseMIT

Advent of Code solutions in Rust by TBali

rust v1.85 build AoC stars license

This repo contains my AoC solutions in Rust, and a simple CLI runner. The first 9 seasons I originally solved in PHP, and later rewrote some solutions (~3.5 seasons) in Rust. From season 2024 I solved the puzzles first in Rust (and rewrote them in PHP later).

Usage

# -- setup
# install Rust: https://www.rust-lang.org/tools/install
rustup update stable
# -- info
cargo version
cargo tree
# -- lint
cargo audit
cargo check
cargo fmt
cargo clippy
# -- doc
cargo doc --no-deps --document-private-items --open
# -- test
cargo nextest run # needs cargo plugin: <https://nexte.st/>
cargo test
cargo test 2024
cargo test 2024day01
cargo test cli
# in Powershell:
$Env:RUST_BACKTRACE=1; cargo test
cargo run
cargo run -- 2024
cargo run -- 2024 1
# -- run
cargo build --release
target/release/aoc.exe
target/release/aoc.exe 2024
target/release/aoc.exe 2024 1
cargo run --release
# -- shortcut run (Windows)
./aoc.bat
./aoc.bat 2024
./aoc.bat 2024 1
./aoc.bat --help
# -- shortcut qa+run (Windows)
./qa.ps1
# -- cleanup
cargo clean

Adding a new solution

  • for puzzle year YYYY, day DD:
  • add puzzle input in input/YYYY/AocYYYYDayDD.txt and example inputs in ...exX.txt
  • add and edit source in src/aocYYYY/aocYYYYdayDD.rs, using the template in src/aocYYYYdayDD.rs
    • update pub fn metadata(), write solve(), add unit tests as needed
  • edit src/aocYYYY.rs:
    • uncomment the pub mod aocYYYYdayDD; line
    • update the PUZZLES list: replace None with Some(...)
  • for a completely new season:
    • edit src/lib.rs: add a pub mod aocYYYY; line
    • edit src/aoc.rs: increase MAX_SEASONS and add a Some(...) item to PUZZLES
    • add and update src/aocYYYY.rs using the template in src/aocYYYY.rs