pub mod input; pub mod error; pub mod days; use days::*; use std::env; use crate::error::AdventError; fn main() -> Result<(), AdventError> { let days = vec![ (day1::one as fn() -> Result, day1::two as fn() -> Result), (day2::one as fn() -> Result, day2::two as fn() -> Result), (day3::one as fn() -> Result, day3::two as fn() -> Result), (day4::one as fn() -> Result, day4::two as fn() -> Result), (day5::one as fn() -> Result, day5::two as fn() -> Result), (day6::one as fn() -> Result, day6::two as fn() -> Result), (day7::one as fn() -> Result, day7::two as fn() -> Result), (day8::one as fn() -> Result, day8::two as fn() -> Result), (day9::one as fn() -> Result, day9::two as fn() -> Result), (day10::one as fn() -> Result, day10::two as fn() -> Result), ]; if env::args().len() == 1 { Ok(days.into_iter().map(|(one, two)| { let one_result = one()?; let two_result = two()?; Ok((one_result, two_result)) }).enumerate().map(|(index, r): (usize, Result<(u64, u64), AdventError>)| { match r { Ok((res1, res2)) => println!("{}: ({}, {})", index + 1, res1, res2), Err(e) => println!("Error: {}", e.0) }; }).fold((), |acc, _| { acc })) } else { let day_index = env::args().nth(1).ok_or(AdventError("Failed to parse day".into()))?.parse::()? - 1; let (one, two) = days[day_index]; if env::args().len() == 3 { match env::args().nth(2).unwrap().parse::()? { 1 => Ok(println!("1: {}", one()?)), 2 => Ok(println!("2: {}", two()?)), _ => return Err(AdventError("part must be either 1 or 2".into())) } } else { Ok(println!("{}: ({}, {})", day_index + 1, one()?, two()?)) } } }