From ec9f1e92bc4731a126eccf3f5ea511003f576f84 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Wed, 7 Dec 2022 10:50:17 +0100 Subject: [PATCH] Rust Day 7 - Better `cd /` --- rust/src/day07/part_1.rs | 5 ++--- rust/src/day07/part_2.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rust/src/day07/part_1.rs b/rust/src/day07/part_1.rs index 3598f14..c6a0ab7 100644 --- a/rust/src/day07/part_1.rs +++ b/rust/src/day07/part_1.rs @@ -9,9 +9,8 @@ pub(crate) fn part_1(input: &Vec) -> usize { for line in input { match line { ConsoleLine::MoveRoot => { - while current_directory.len() > 1 { - current_directory.pop(); - } + current_directory.clear(); + current_directory.push(""); } ConsoleLine::MoveUp => { current_directory.pop(); diff --git a/rust/src/day07/part_2.rs b/rust/src/day07/part_2.rs index f70c957..9488b95 100644 --- a/rust/src/day07/part_2.rs +++ b/rust/src/day07/part_2.rs @@ -11,9 +11,8 @@ pub(crate) fn part_2(input: &Vec) -> usize { for line in input { match line { ConsoleLine::MoveRoot => { - while current_directory.len() > 1 { - current_directory.pop(); - } + current_directory.clear(); + current_directory.push(""); } ConsoleLine::MoveUp => { current_directory.pop();