From ac8125750abed263619da4cc6d653bb5ab76f007 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 13 Dec 2021 00:36:34 +0300 Subject: 2021, day6: done --- 2021/day6/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2021/day6/src/main.rs (limited to '2021/day6/src') diff --git a/2021/day6/src/main.rs b/2021/day6/src/main.rs new file mode 100644 index 0000000..378764e --- /dev/null +++ b/2021/day6/src/main.rs @@ -0,0 +1,33 @@ +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::()); +} -- cgit v1.2.3-70-g09d2