From ab0931c9c1c3b3c13e6dcee854801860dce109d2 Mon Sep 17 00:00:00 2001 From: Dave Farnham Date: Tue, 14 Jan 2025 09:42:57 -0700 Subject: [PATCH] Factor out a multiplication --- src/year2022/day20.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/year2022/day20.rs b/src/year2022/day20.rs index 1d2e6588..f1cf32e7 100644 --- a/src/year2022/day20.rs +++ b/src/year2022/day20.rs @@ -109,9 +109,9 @@ fn decrypt(input: &[i64], key: i64, rounds: usize) -> i64 { let indices: Vec<_> = mixed.into_iter().flatten().flatten().collect(); let zeroth = indices.iter().position(|&i| numbers[i] == 0).unwrap(); - [1000, 2000, 3000] + key * [1000, 2000, 3000] .iter() .map(|offset| (zeroth + offset) % indices.len()) - .map(|index| input[indices[index]] * key) - .sum() + .map(|index| input[indices[index]]) + .sum::() }