Skip to content

Instantly share code, notes, and snippets.

@neofight78
Last active December 6, 2021 08:55
Show Gist options
  • Save neofight78/39df0cf8a966e69b2cc4e8f78ace44da to your computer and use it in GitHub Desktop.
Save neofight78/39df0cf8a966e69b2cc4e8f78ace44da to your computer and use it in GitHub Desktop.
Advent of Code 2021 - Day 6: Lanternfish
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