Created
December 6, 2021 22:10
-
-
Save aaronjeline/e1c031979d2c932dd80b1d630a5369f3 to your computer and use it in GitHub Desktop.
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
use std::fs::read_to_string; | |
const DAYS: usize = 256; | |
type Fish = Vec<u64>; | |
fn main() { | |
let mut fish = vec![0; 9]; | |
let mut scratch; | |
parse_input(&mut fish); | |
for _ in 0..DAYS { | |
scratch = vec![0; 9]; | |
let mut pos = 8; | |
while pos != 0 { | |
scratch[pos - 1] = fish[pos]; | |
pos -= 1; | |
} | |
scratch[8] = fish[0]; | |
scratch[6] += fish[0]; | |
fish = scratch; | |
} | |
println!("Total: {}", fish.iter().sum::<u64>()); | |
} | |
fn parse_input(fish: &mut Fish) { | |
let s = read_to_string("/tmp/input").expect("File I/O"); | |
for entry in s.trim_end().split(",") { | |
match entry.parse::<usize>() { | |
Ok(n) => fish[n] += 1, | |
Err(_) => println!("err on: {}", entry), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment