From 7f212eeebc7e0669e23ee5c5e276251a4cfaddc7 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Thu, 14 Dec 2023 21:41:20 +0100 Subject: [PATCH] fix when cycle_remainder is 0 --- 14/day14.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/14/day14.rs b/14/day14.rs index fc8b404..1fc9244 100644 --- a/14/day14.rs +++ b/14/day14.rs @@ -88,8 +88,11 @@ fn main() { } rocks_store.push(rocks.clone()); } - // do the cycles that remain after the ... Cycle - for _ in 0..(1_000_000_000 as usize - cycle_start) % cycle_length - 1 { + // do the cycles that remain after the ... Cycle - 1 + let mut cycle_remainder = (1_000_000_000 as usize - cycle_start) % cycle_length; + if cycle_remainder == 0 { cycle_remainder = cycle_length - 1 } + else { cycle_remainder -= 1 } + for _ in 0..cycle_remainder { tilt(&mut rocks, north_at, ns_xlen, ns_ylen); tilt(&mut rocks, west_at, ew_xlen, ew_ylen); tilt(&mut rocks, south_at, ns_xlen, ns_ylen);