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:
parent
152773a0a9
commit
f083a70ae5
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue