use std::error::Error; use std::fs::File; use std::io::{self, BufRead}; use std::vec::Vec; fn main() -> Result<(), Box> { let file = File::open("inputs/day13.txt")?; let mut lines = io::BufReader::new(file).lines().map(|l| l.unwrap()); let depature_time: u32 = lines.nth(0).unwrap().parse().unwrap(); let buses: Vec = lines .nth(0) .unwrap() .split(',') .filter_map(|b| b.parse().ok()) .collect(); let times: Vec<(u32, u32)> = buses .iter() .map(|b| (*b, b - (depature_time % b))) .collect(); let best_time = times .iter() .fold(times[0], |a, b| if a.1 < b.1 { a } else { *b }); println!("Line: {}, Wait Time: {}", best_time.0, best_time.1); println!("Answer: {}", best_time.0 * best_time.1); Ok(()) }