Solution for 2021: day 6
[?]
Dec 10, 2021, 2:05 AM
XNSA4VSTUFEDHTSTTIR2RQVPK7JH7TBJFU3VMIMDAECEKN2GBATQCDependencies
- [2]
M2AJCSV3Solution for 2021 day 5 - [3]
M7EGDCFHRemove unused code - [*]
HUHAFQLN2021 day 1 - [*]
TNWJK3WAApply cargo clippy
Change contents
- file addition: day6.rs[5.16]
fn main() {use std::io::BufRead;let mut pops: [u128; 9] = [0; 9];let filename = std::env::args().nth(1).expect("Expected filename");let file = std::io::BufReader::new(std::fs::File::open(<String as AsRef<std::path::Path>>::as_ref(&filename,)).unwrap(),);for i in file.split(b',') {let i: usize = std::str::from_utf8(&i.unwrap()).unwrap().trim().parse().unwrap();pops[i] += 1;}for g in 1..=256 {let mut next: [u128; 9] = [0; 9];for (i, p) in pops.iter().enumerate() {for j in advance_lanternfish(i as u8) {next[j as usize] += p;}}pops = next;if g == 80 || g == 256 {println!("Day {}: {}", g, pops.iter().sum::<u128>());}}}fn advance_lanternfish(timer: u8) -> Box<dyn Iterator<Item = u8>> {use std::iter::once;if timer == 0 {Box::new(once(6).chain(once(8)))} else {Box::new(once(timer - 1))}} - edit in 2021/day5.rs at line 136
- edit in 2021/Cargo.toml at line 30[6.1457]
[[bin]]name = "day6"path = "day6.rs"