Make it more cursed lmao
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julius 2021-12-06 09:35:05 +01:00
parent d7d1a1d840
commit f2f63bbc47
Signed by: j00lz
GPG key ID: AF241B0AA237BBA2

View file

@ -1,4 +1,3 @@
use std::collections::HashMap;
use crate::Day; use crate::Day;
pub struct Day06(Vec<u8>); pub struct Day06(Vec<u8>);
@ -18,34 +17,20 @@ impl Day for Day06 {
} }
impl Day06 { impl Day06 {
fn do_hashmap_magic(&self, days: u64) -> u64 { fn do_hashmap_magic(&self, days: u64) -> u64 {
let x = self.0.clone(); let x = self.0.clone();
let mut hm = HashMap::<u8, u64>::new(); let mut w: [u64; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0];
for z in x { for z in x {
let e = hm.entry(z).or_insert(0); w[z as usize] += 1;
*e += 1;
} }
for _ in 0..days { for _ in 0..days {
let mut to_add = 0; w = Self::foo(w);
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;
}
} }
hm.values().sum::<u64>() 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]
} }
} }