summaryrefslogtreecommitdiff
path: root/day6/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-12-08 20:11:07 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-12-08 20:11:07 +0100
commit772a3db1831d4ccfed172e659b92db47cba7ee70 (patch)
tree9ef0b5b5bd4ee698740b593c2985f4381abee740 /day6/src
parentc20904eab90f472d9f94334e52594611af6a4496 (diff)
Add day6, slowly
Diffstat (limited to 'day6/src')
-rw-r--r--day6/src/main.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/day6/src/main.rs b/day6/src/main.rs
new file mode 100644
index 0000000..46a148c
--- /dev/null
+++ b/day6/src/main.rs
@@ -0,0 +1,36 @@
+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(())
+}