use std::{fs, env}; fn read_input(path: &str) -> String { return fs::read_to_string(path).expect("Cannot read file."); } fn parse_input(s: &str) -> Vec { return s.replace("\n", "").split(",") .filter_map(|e| e.parse::().ok()).collect(); } fn smart_compute_x_days(v: &Vec, x: i32) -> i128 { let mut l: Vec = vec![0;9]; for i in v { l[*i as usize] += 1; } for _d in 1..=x { let n = l[0]; for i in 1..9 { l[i - 1] = l[i]; } l[6] += n; l[8] = n; } return l.iter().sum(); } fn main() { let args: Vec = env::args().collect(); for arg in args.iter().skip(1) { let vec_in = parse_input(&read_input(&arg)); println!("[{}]", &arg); println!("\t[Part 1] => Answer is '{}'.", smart_compute_x_days(&vec_in, 80)); println!("\t[Part 2] => Answer is '{}'.", smart_compute_x_days(&vec_in, 256)); } }