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/Cargo.toml | 9 +++++++++ 2021/day6/input | 1 + 2021/day6/input.example | 1 + 2021/day6/src/main.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 2021/day6/Cargo.toml create mode 100644 2021/day6/input create mode 100644 2021/day6/input.example create mode 100644 2021/day6/src/main.rs diff --git a/2021/day6/Cargo.toml b/2021/day6/Cargo.toml new file mode 100644 index 0000000..9957f8b --- /dev/null +++ b/2021/day6/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day6" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.10.3" diff --git a/2021/day6/input b/2021/day6/input new file mode 100644 index 0000000..9bb513a --- /dev/null +++ b/2021/day6/input @@ -0,0 +1 @@ +1,1,3,5,3,1,1,4,1,1,5,2,4,3,1,1,3,1,1,5,5,1,3,2,5,4,1,1,5,1,4,2,1,4,2,1,4,4,1,5,1,4,4,1,1,5,1,5,1,5,1,1,1,5,1,2,5,1,1,3,2,2,2,1,4,1,1,2,4,1,3,1,2,1,3,5,2,3,5,1,1,4,3,3,5,1,5,3,1,2,3,4,1,1,5,4,1,3,4,4,1,2,4,4,1,1,3,5,3,1,2,2,5,1,4,1,3,3,3,3,1,1,2,1,5,3,4,5,1,5,2,5,3,2,1,4,2,1,1,1,4,1,2,1,2,2,4,5,5,5,4,1,4,1,4,2,3,2,3,1,1,2,3,1,1,1,5,2,2,5,3,1,4,1,2,1,1,5,3,1,4,5,1,4,2,1,1,5,1,5,4,1,5,5,2,3,1,3,5,1,1,1,1,3,1,1,4,1,5,2,1,1,3,5,1,1,4,2,1,2,5,2,5,1,1,1,2,3,5,5,1,4,3,2,2,3,2,1,1,4,1,3,5,2,3,1,1,5,1,3,5,1,1,5,5,3,1,3,3,1,2,3,1,5,1,3,2,1,3,1,1,2,3,5,3,5,5,4,3,1,5,1,1,2,3,2,2,1,1,2,1,4,1,2,3,3,3,1,3,5 diff --git a/2021/day6/input.example b/2021/day6/input.example new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/2021/day6/input.example @@ -0,0 +1 @@ +3,4,3,1,2 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