advent-of-code

advent of code (partial solutions)
Log | Files | Refs | README

commit 71d72375c0d602914e990741dfe657cff2fd9f0d
parent 37adb071262339a5ebdf7a67842f6ea1c9ab8ee3
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon,  6 Dec 2021 01:43:20 -0800

ez day 6

Diffstat:
A2021/aoc06.rs | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/2021/aoc06.rs b/2021/aoc06.rs @@ -0,0 +1,25 @@ +use std::collections::HashSet; +use std::error::Error; +use std::io::{self, Read}; + +fn main() -> Result<(), Box<dyn Error>> { + let mut state: [usize; 9] = [0; 9]; + let mut stdin = io::stdin(); + let mut input = String::new(); + stdin.read_to_string(&mut input); + for i in input.trim().split(",").map(|n| n.parse::<usize>().unwrap()) { + state[i] += 1; + } + for days in 0..257 { + if days == 80 || days == 256 { + println!("{}", state.iter().sum::<usize>()); + } + let repros = state[0]; + for i in 1..state.len() { + state[i - 1] = state[i]; + } + state[6] += repros; + state[8] = repros; + } + Ok(()) +}