diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-12-05 19:46:06 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-12-05 19:46:06 +0100 |
commit | cf6303a5bc1558ebdb7b467da38f74cd3ac3a9b1 (patch) | |
tree | 6292cb239a8cf114179c6e7c8b3015840dfbae6e /day6/src | |
parent | 6e10cc2773fcaff64902b13f44443da014f38be7 (diff) |
Add 2022
Diffstat (limited to 'day6/src')
-rw-r--r-- | day6/src/main.rs | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/day6/src/main.rs b/day6/src/main.rs deleted file mode 100644 index 46a148c..0000000 --- a/day6/src/main.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::fs::File; -use std::io::{BufRead, BufReader}; - -fn main() -> std::io::Result<()> { - let file = File::open("input.txt")?; - let mut reader = BufReader::new(file); - let mut buffer = String::new(); - - reader.read_line(&mut buffer)?; - - let mut lanternfishes: Vec<_> = buffer - .trim() - .split(',') - .map(|x| x.parse::<i16>().unwrap()) - .collect::<Vec<i16>>(); - - for _ in 0..80 { - let mut n = 0; - for lanternfish in lanternfishes.iter_mut() { - if *lanternfish == 0 { - *lanternfish = 6; - n += 1; - } else { - *lanternfish -= 1; - } - } - - for _ in 0..n { - lanternfishes.push(8); - } - } - - println!("{}", lanternfishes.len()); - - Ok(()) -} |