summaryrefslogtreecommitdiffstats
path: root/2021/day6/src
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/src
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/src')
-rw-r--r--2021/day6/src/main.rs33
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 @@
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}