From dc477f42828a7ad6509ed1238a9c96fc5d7ee757 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 28 Dec 2023 14:04:04 +0100 Subject: [PATCH] Clean up Day 21 --- src/bin/day21.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bin/day21.rs b/src/bin/day21.rs index 788cbdc..e41b529 100644 --- a/src/bin/day21.rs +++ b/src/bin/day21.rs @@ -106,18 +106,18 @@ fn bfs(plot: &Plot) -> Vec { distance += 1; } - return distances; + distances } fn interpolate(x0: usize, mut ys: [i64; 4], x: usize) -> Option { assert!(x >= x0); if x <= x0 + 3 { - Some(ys[(x - x0) as usize]) + Some(ys[x - x0]) } else { let mut f = [0; 4]; - for i in 0..4 { - f[i] = ys[0]; + for coef in &mut f { + *coef = ys[0]; for i in 0..ys.len() - 1 { ys[i] = ys[i + 1] - ys[i]; } @@ -125,7 +125,7 @@ fn interpolate(x0: usize, mut ys: [i64; 4], x: usize) -> Option { let xa = (x - x0) as i64; let xb = xa * (x - x0 - 1) as i64; - (f[3] == 0).then_some(f[0] + f[1] * xa as i64 + f[2] * xb / 2) + (f[3] == 0).then_some(f[0] + f[1] * xa + f[2] * xb / 2) } } @@ -153,7 +153,7 @@ fn main() -> Result<()> { assert!(plot.height == plot.width); let side_length = width; let required_scale = - |step_count| (step_count - plot.start.0 as usize + side_length) / side_length; + |step_count| (step_count - plot.start.0 + side_length) / side_length; let offset = STEPS_P2 % side_length; let max_scale = required_scale(STEPS_P2); @@ -168,8 +168,8 @@ fn main() -> Result<()> { plot.scale_to(scale0 + 3); let distances = bfs(&plot); - for i in 0..4 { - sequence[i] = positions(&distances, (offset + i * side_length) as u64) as i64; + for (i, seq) in sequence.iter_mut().enumerate() { + *seq = positions(&distances, (offset + i * side_length) as u64) as i64; } let mut n = 0;