aocrust/src/main.rs
2024-12-03 02:06:24 +01:00

54 lines
1.6 KiB
Rust

mod solution;
use solution::solution;
mod input_data;
use input_data::load_actual;
mod fetch_input;
use fetch_input::fetch_input;
use std::{path::Path, time::Instant, env};
fn main() {
let year = env::var("ADVENT_YEAR")
.unwrap_or("2024".into())
.parse()
.unwrap();
let day = env::var("ADVENT_DAY")
.unwrap_or("1".into())
.parse()
.unwrap();
if ! Path::new(&format!("./data/{}/day{:02}", year, day)).exists()
&& env::var("ADVENT_TOKEN").is_ok() {
fetch_input(year, day).expect("Set ADVENT_TOKEN to the correct session cookie to fetch input automatically");
}
run_all();
}
fn run_all() {
let years_to_run = [2023, 2024];
if env::var("ADVENT_TOKEN").is_ok() {
for year in years_to_run {
for day in 1..=25 {
println!("Pre-fetching input for {year}/{:02}", day);
fetch_input(year, day).expect("Set ADVENT_TOKEN to the correct session cookie to fetch input automatically");
}
}
}
for year in years_to_run {
for day in 1..=25 {
for part in [1, 2] {
let input = load_actual(year, day).unwrap_or_else(|_| panic!("Missing input for {}/{:02}", year, day));
let now = Instant::now();
let result = solution(&input, year, day, part).unwrap_or_else(|| panic!("No solution at {}/{:02}", year, day));
let time_passed = now.elapsed().as_millis();
println!("Running Year {}, Day {:02}, Part {} - Result {} - took {}ms", year, day, part, result, time_passed);
}
}
}
}