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.
This commit is contained in:
MasterofJOKers 2022-12-18 18:31:23 +01:00
parent 152773a0a9
commit f083a70ae5
1 changed files with 5 additions and 0 deletions

View File

@ -51,8 +51,13 @@ fn main() -> Result<(), Box<dyn error::Error>> {
// println!("{:?}", re.captures(&line));
// println!("{:?}", items);
let cap: Vec<usize> = 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);
}
}