aoc2024/src/main.rs
2024-12-04 08:59:07 +01:00

32 lines
957 B
Rust

use std::{fmt::Display, fs::read_to_string, time::Instant};
mod day01;
mod day02;
mod day03;
mod day04;
fn main() {
color_eyre::install().unwrap();
tracing_subscriber::fmt::init();
solve_day(1, day01::pt1, day01::pt2);
solve_day(2, day02::pt1, day02::pt2);
solve_day(3, day03::pt1, day03::pt2);
solve_day(4, day04::pt1, day04::pt2);
}
fn solve_day<Fa, Fb, Ta, Tb>(day: u8, part_a: Fa, part_b: Fb)
where
Fa: Fn(&str) -> Ta,
Ta: Display,
Fb: Fn(&str) -> Tb,
Tb: Display,
{
let input = read_to_string(format!("./inputs/day{day:02}/input.txt"))
.unwrap_or_else(|_| panic!("Missing input.txt for day{day:02}"));
let start = Instant::now();
let result_a = part_a(&input);
tracing::info!("[{day:02}] Part A: {result_a} \tin {:?}", start.elapsed());
let start = Instant::now();
let result_b = part_b(&input);
tracing::info!("[{day:02}] Part B: {result_b} \tin {:?}", start.elapsed());
}