From 2a9dd4c3f2d16cd4976738e5bdce29b4f4dc31d5 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 9 Dec 2024 15:59:38 +0100 Subject: [PATCH] Add one comment :D --- src/day09.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/day09.rs b/src/day09.rs index 8ad49bb..eac0b8c 100644 --- a/src/day09.rs +++ b/src/day09.rs @@ -69,7 +69,7 @@ pub fn defrag_v2(mut memory: Vec) -> Vec { let mut files: Vec = Vec::new(); let mut pos = 0; - loop { + while pos < memory.len() { let start = pos; let v = memory[start]; pos += 1; @@ -87,14 +87,11 @@ pub fn defrag_v2(mut memory: Vec) -> Vec { } else { files.push(chunk); } - - if pos == memory.len() { - break; - } } for f in files.iter().rev() { for free_space in free_spaces.iter_mut() { + // Files are only move backward. if free_space.pos >= f.pos { break; } -- 2.45.2