this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 33 lines 900 B view raw
1fn main() { 2 let input = std::fs::read_to_string("input.txt").unwrap(); 3 let start: Vec<usize> = input.split(",").map(|str| str.parse().unwrap()).collect(); 4 5 println!("Part 1: {}", iterate_fish(start.clone(), 80)); 6 println!("Part 2: {}", iterate_fish(start.clone(), 256)); 7} 8 9#[test] 10fn test_part1() { 11 let start: Vec<usize> = vec![3,4,3,1,2]; 12 assert_eq!(iterate_fish(start.clone(), 18), 26); 13 assert_eq!(iterate_fish(start.clone(), 80), 5934); 14} 15 16fn iterate_fish(fish: Vec<usize>, n: usize) -> u64 { 17 let mut counts: Vec<u64> = vec![0; 9]; 18 for f in fish { 19 counts[f] += 1; 20 } 21 22 for _ in 0..n { 23 let mut new_counts = counts.clone(); 24 for i in (1..=8).rev() { 25 new_counts[i-1] = counts[i]; 26 } 27 new_counts[6] += counts[0]; 28 new_counts[8] = counts[0]; 29 counts = new_counts; 30 } 31 32 counts.iter().sum() 33}