diff --git a/day5/src/main.rs b/day5/src/main.rs index c18499c..8ca9b51 100644 --- a/day5/src/main.rs +++ b/day5/src/main.rs @@ -98,10 +98,17 @@ fn simulate_stack_operation(mut stacks: Vec>, instruction: [u32; let target: u32 = instruction[2]-1; //println!("Executing instruction {:?}", instruction); - for _ in 0..amount { // do the instruction amount times + let mut crane_stack: Vec = Vec::new(); + for _ in 0..amount { // fetch amount-many crates onto the crane stack let c: char = stacks[source as usize].pop_back().unwrap(); - //println!("Took crate {} from stack #{} and placed it onto stack #{}", c, source, target); + crane_stack.push(c); + println!("Took crate {} from stack #{} and placed it onto the crane stack {:?}", c, source, crane_stack); + } + + for _ in 0..amount { // drop all crates in the crane stack onto the target stack + let c: char = crane_stack.pop().unwrap(); stacks[target as usize].push_back(c); + println!("Placed crate {} from the crane stack onto target stack #{}", c, target); } return stacks;