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/day6/src | |
parent | 54cbcaa842ea9032c850158183eeba45909e26e2 (diff) | |
download | aoc-ac8125750abed263619da4cc6d653bb5ab76f007.tar.gz aoc-ac8125750abed263619da4cc6d653bb5ab76f007.tar.bz2 aoc-ac8125750abed263619da4cc6d653bb5ab76f007.zip |
2021, day6: done
Diffstat (limited to '2021/day6/src')
-rw-r--r-- | 2021/day6/src/main.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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 | } | ||