From f2f63bbc47a51a1b98af540f88f40dba61ba205c Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Mon, 6 Dec 2021 09:35:05 +0100 Subject: [PATCH] Make it more cursed lmao --- src/day06.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/day06.rs b/src/day06.rs index 8cbeac4..b9fd7d5 100644 --- a/src/day06.rs +++ b/src/day06.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use crate::Day; pub struct Day06(Vec); @@ -18,34 +17,20 @@ impl Day for Day06 { } impl Day06 { + fn do_hashmap_magic(&self, days: u64) -> u64 { let x = self.0.clone(); - let mut hm = HashMap::::new(); + let mut w: [u64; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; for z in x { - let e = hm.entry(z).or_insert(0); - *e += 1; + w[z as usize] += 1; } for _ in 0..days { - let mut to_add = 0; - for num in 0..=8 { - if num == 0 { - to_add = *hm.get(&0).unwrap_or(&0); - } else { - let entry = { *hm.get(&num).unwrap_or(&0) }; - let prev = hm.entry(num - 1).or_insert(0); - *prev = entry; - } - } - { - let en = hm.entry(8).or_insert(0); - *en = to_add; - } - { - let en = hm.entry(6).or_insert(0); - *en += to_add; - } + w = Self::foo(w); } - hm.values().sum::() + w.iter().sum() + } + fn foo([a, b, c, d, e, f, g, h, i]: [u64; 9]) -> [u64; 9] { + [b, c, d, e, f, g, h + a, i, a] } }