41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use std::{fs::read_to_string};
|
|
|
|
const ITERATIONS: u32 = 256;
|
|
const NEW_FISH_LIFETIME: u8 = 8;
|
|
|
|
fn main() {
|
|
let input_char_vec = read_to_string("./input.txt").expect("ERROR reading file");
|
|
let split_input = input_char_vec.split(",").collect::<Vec<&str>>();
|
|
let mut fish: Vec<u8> = split_input.iter().map(
|
|
|x| x.parse::<u8>().unwrap()
|
|
).collect();
|
|
|
|
print_fish(&fish, -1);
|
|
|
|
for _i in 1..ITERATIONS + 1 {
|
|
for fi in 0..fish.len() {
|
|
let current_timer = fish[fi];
|
|
if current_timer == 0 {
|
|
fish[fi] = 6;
|
|
fish.push(NEW_FISH_LIFETIME);
|
|
} else {
|
|
fish[fi] = current_timer - 1;
|
|
}
|
|
}
|
|
println!("Interation {} of {}, {}", _i, ITERATIONS, fish.len());
|
|
//print_fish(&fish, _i as i32);
|
|
}
|
|
|
|
|
|
println!("Final Number of Fish: {}", fish.len());
|
|
}
|
|
|
|
fn print_fish(fish: &Vec<u8>, iteration: i32){
|
|
let fish_copy = fish.to_owned();
|
|
print!("Iteration: {}, Fish: ", iteration);
|
|
for f in fish_copy {
|
|
print!("{}, ", f);
|
|
}
|
|
print!("\n");
|
|
}
|