use std::env; fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { eprintln!("Usage: {} ", args[0]); std::process::exit(1); } let mut smart_lanternfish: [u64; 9] = [0; 9]; let foo: String = std::fs::read_to_string(&args[1]).unwrap().parse().unwrap(); let mut lanternfish: Vec = Vec::new(); lanternfish.extend(foo.trim().split(",").map(|x| x.parse::().unwrap())); for initial_fish in &lanternfish { smart_lanternfish[*initial_fish as usize] += 1; } // println!("{:?}", smart_lanternfish); for _day in 0..256 { smart_lanternfish.rotate_left(1); smart_lanternfish[6] += smart_lanternfish[8]; // println!( // "After {day:>width$} days: {lanternfish:?}", // day = _day, // width = 2, // lanternfish = smart_lanternfish // ); } println!("{}", smart_lanternfish.iter().sum::()); }