Add args to Rust program to run individual days

bram-benchmarks
Bram 2025-12-01 17:13:18 +01:00
parent ca7f0d2d28
commit 32bacbeb1d
2 changed files with 35 additions and 1 deletions

View File

@ -15,7 +15,7 @@ use std::time::Duration;
use crate::utils::read_from_file; use crate::utils::read_from_file;
use crate::utils::diagnostics; use crate::utils::diagnostics;
type DailyOutput = ( u128, u128, Duration ); pub type DailyOutput = ( u128, u128, Duration );
pub use crate::utils::diagnostics::AdventOfCode; pub use crate::utils::diagnostics::AdventOfCode;

View File

@ -1,4 +1,31 @@
fn main() { fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let day : Option<u8> = args[1].parse().ok();
match day {
Some(1) => run_day(aoc2025::day_01),
// Some(2) => run_day(aoc2025::day_02),
// Some(3) => run_day(aoc2025::day_03),
// Some(4) => run_day(aoc2025::day_04),
// Some(5) => run_day(aoc2025::day_05),
// Some(6) => run_day(aoc2025::day_06),
// Some(7) => run_day(aoc2025::day_07),
// Some(8) => run_day(aoc2025::day_08),
// Some(9) => run_day(aoc2025::day_09),
// Some(10) => run_day(aoc2025::day_10),
// Some(11) => run_day(aoc2025::day_11),
// Some(12) => run_day(aoc2025::day_12),
Some(_) => run_all_days(),
None => run_all_days(),
}
} else {
run_all_days();
}
}
fn run_all_days() {
let mut aoc = aoc2025::AdventOfCode::new(); let mut aoc = aoc2025::AdventOfCode::new();
aoc.insert(1, aoc2025::day_01()); aoc.insert(1, aoc2025::day_01());
@ -16,3 +43,10 @@ fn main() {
aoc.show_diagnostics(); aoc.show_diagnostics();
} }
fn run_day(day : fn() -> aoc2025::DailyOutput) {
let (p1, p2, _) = day();
println!("Part 1: {}", p1);
println!("Part 2: {}", p2);
}