summaryrefslogtreecommitdiffstats
path: root/2021/day6
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:38:11 +0300
committerYigit Sever2021-12-13 10:38:11 +0300
commit74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch)
treee27db4cd0873c81a53d32277446d926d176304e0 /2021/day6
parent3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff)
parentac8125750abed263619da4cc6d653bb5ab76f007 (diff)
downloadaoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2021/day6')
-rw-r--r--2021/day6/Cargo.toml9
-rw-r--r--2021/day6/input1
-rw-r--r--2021/day6/input.example1
-rw-r--r--2021/day6/src/main.rs33
4 files changed, 44 insertions, 0 deletions
diff --git a/2021/day6/Cargo.toml b/2021/day6/Cargo.toml
new file mode 100644
index 0000000..9957f8b
--- /dev/null
+++ b/2021/day6/Cargo.toml
@@ -0,0 +1,9 @@
1[package]
2name = "day6"
3version = "0.1.0"
4edition = "2021"
5
6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
8[dependencies]
9itertools = "0.10.3"
diff --git a/2021/day6/input b/2021/day6/input
new file mode 100644
index 0000000..9bb513a
--- /dev/null
+++ b/2021/day6/input
@@ -0,0 +1 @@
1,1,3,5,3,1,1,4,1,1,5,2,4,3,1,1,3,1,1,5,5,1,3,2,5,4,1,1,5,1,4,2,1,4,2,1,4,4,1,5,1,4,4,1,1,5,1,5,1,5,1,1,1,5,1,2,5,1,1,3,2,2,2,1,4,1,1,2,4,1,3,1,2,1,3,5,2,3,5,1,1,4,3,3,5,1,5,3,1,2,3,4,1,1,5,4,1,3,4,4,1,2,4,4,1,1,3,5,3,1,2,2,5,1,4,1,3,3,3,3,1,1,2,1,5,3,4,5,1,5,2,5,3,2,1,4,2,1,1,1,4,1,2,1,2,2,4,5,5,5,4,1,4,1,4,2,3,2,3,1,1,2,3,1,1,1,5,2,2,5,3,1,4,1,2,1,1,5,3,1,4,5,1,4,2,1,1,5,1,5,4,1,5,5,2,3,1,3,5,1,1,1,1,3,1,1,4,1,5,2,1,1,3,5,1,1,4,2,1,2,5,2,5,1,1,1,2,3,5,5,1,4,3,2,2,3,2,1,1,4,1,3,5,2,3,1,1,5,1,3,5,1,1,5,5,3,1,3,3,1,2,3,1,5,1,3,2,1,3,1,1,2,3,5,3,5,5,4,3,1,5,1,1,2,3,2,2,1,1,2,1,4,1,2,3,3,3,1,3,5
diff --git a/2021/day6/input.example b/2021/day6/input.example
new file mode 100644
index 0000000..55129f1
--- /dev/null
+++ b/2021/day6/input.example
@@ -0,0 +1 @@
3,4,3,1,2
diff --git a/2021/day6/src/main.rs b/2021/day6/src/main.rs
new file mode 100644
index 0000000..378764e
--- /dev/null
+++ b/2021/day6/src/main.rs
@@ -0,0 +1,33 @@
1use std::env;
2
3fn main() {
4 let args: Vec<String> = env::args().collect();
5
6 if args.len() != 2 {
7 eprintln!("Usage: {} <filename>", args[0]);
8 std::process::exit(1);
9 }
10 let mut smart_lanternfish: [u64; 9] = [0; 9];
11
12 let foo: String = std::fs::read_to_string(&args[1]).unwrap().parse().unwrap();
13 let mut lanternfish: Vec<u8> = Vec::new();
14 lanternfish.extend(foo.trim().split(",").map(|x| x.parse::<u8>().unwrap()));
15
16 for initial_fish in &lanternfish {
17 smart_lanternfish[*initial_fish as usize] += 1;
18 }
19
20 // println!("{:?}", smart_lanternfish);
21 for _day in 0..256 {
22 smart_lanternfish.rotate_left(1);
23 smart_lanternfish[6] += smart_lanternfish[8];
24 // println!(
25 // "After {day:>width$} days: {lanternfish:?}",
26 // day = _day,
27 // width = 2,
28 // lanternfish = smart_lanternfish
29 // );
30 }
31
32 println!("{}", smart_lanternfish.iter().sum::<u64>());
33}