From 60b77d5d3da9d5b929342cececd7590b0d1a8f93 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 6 Dec 2021 18:06:13 -0800 Subject: [PATCH] day 6 part 2 Use rotate_left --- 2021/src/day6.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/2021/src/day6.rs b/2021/src/day6.rs index 3e8e985..52a0d6e 100644 --- a/2021/src/day6.rs +++ b/2021/src/day6.rs @@ -88,16 +88,10 @@ fn part2(input: &str) -> Result { .into_iter() .for_each(|n| counts[n] += 1); for _ in 0..256 { - let mut tmp = [0; 9]; - for i in 0..9 { - if i == 0 { - tmp[6] += counts[0]; - tmp[8] += counts[0]; - } else { - tmp[i - 1] += counts[i]; - } - } - counts = tmp; + let ready = counts[0]; + counts.rotate_left(1); + counts[6] += ready; + counts[8] = ready; } Ok(counts.iter().sum()) }