diff options
author | Yigit Sever | 2021-12-13 00:36:34 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 00:36:34 +0300 |
commit | ac8125750abed263619da4cc6d653bb5ab76f007 (patch) | |
tree | f14c05d04e9562b664591f075bb9d9c7935cb6b4 /2021 | |
parent | 54cbcaa842ea9032c850158183eeba45909e26e2 (diff) | |
download | aoc-ac8125750abed263619da4cc6d653bb5ab76f007.tar.gz aoc-ac8125750abed263619da4cc6d653bb5ab76f007.tar.bz2 aoc-ac8125750abed263619da4cc6d653bb5ab76f007.zip |
2021, day6: done
Diffstat (limited to '2021')
-rw-r--r-- | 2021/day6/Cargo.toml | 9 | ||||
-rw-r--r-- | 2021/day6/input | 1 | ||||
-rw-r--r-- | 2021/day6/input.example | 1 | ||||
-rw-r--r-- | 2021/day6/src/main.rs | 33 |
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] | ||
2 | name = "day6" | ||
3 | version = "0.1.0" | ||
4 | edition = "2021" | ||
5 | |||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
7 | |||
8 | [dependencies] | ||
9 | itertools = "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 @@ | |||
1 | use std::env; | ||
2 | |||
3 | fn 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 | } | ||