diff options
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 | } | ||
