Last active
December 6, 2021 08:55
-
-
Save neofight78/39df0cf8a966e69b2cc4e8f78ace44da to your computer and use it in GitHub Desktop.
Advent of Code 2021 - Day 6: Lanternfish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn breed(fish: &[u8], generations: u64) -> u64 { | |
let mut lifetimes = vec![0u64; 9]; | |
fish.iter().for_each(|&f| lifetimes[f as usize] += 1); | |
for _ in 0..generations { | |
lifetimes.rotate_left(1); | |
lifetimes[6] += lifetimes[8]; | |
} | |
lifetimes.iter().sum() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment