summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--day6/Cargo.toml8
-rw-r--r--day6/input.txt1
-rw-r--r--day6/src/main.rs36
4 files changed, 46 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index afacff3..56e5ff2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,2 +1,2 @@
[workspace]
-members = ["day1", "day2", "day3", "day4"]
+members = ["day1", "day2", "day3", "day4", "day6"]
diff --git a/day6/Cargo.toml b/day6/Cargo.toml
new file mode 100644
index 0000000..89d04ae
--- /dev/null
+++ b/day6/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "day6"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/day6/input.txt b/day6/input.txt
new file mode 100644
index 0000000..de918c7
--- /dev/null
+++ b/day6/input.txt
@@ -0,0 +1 @@
+1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1
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(())
+}