From f083a70ae5fc8d8a1d7a47b5f4866834d6abb145 Mon Sep 17 00:00:00 2001 From: MasterofJOKers Date: Sun, 18 Dec 2022 18:31:23 +0100 Subject: [PATCH] day05: Changes for part 2 I feel like there should be away for me to read from the back and move things over directly instead of having a temporary Vec for it, but I'm not sure how this would work with the owner-checking, so I didn't try. --- day05/src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/day05/src/main.rs b/day05/src/main.rs index 466eb24..07659c3 100644 --- a/day05/src/main.rs +++ b/day05/src/main.rs @@ -51,8 +51,13 @@ fn main() -> Result<(), Box> { // println!("{:?}", re.captures(&line)); // println!("{:?}", items); let cap: Vec = re.captures(&line).ok_or("Could not match line")?.iter().skip(1).map(|x| x.unwrap().as_str().parse().unwrap()).collect(); + let mut items_to_move = vec![]; for _ in 0..cap[0] { let item = items[cap[1] - 1].pop().ok_or("Found a broken match")?; + items_to_move.push(item); + } + + for item in items_to_move.iter().rev() { items[cap[2] - 1].push(item); } }