From db39b5079219af288986a9c12b0bdd5c87a5a16a Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Tue, 6 Dec 2022 14:03:58 +0200 Subject: Day6 done in Rust --- 2022/Rust/src/day5.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to '2022/Rust/src/day5.rs') diff --git a/2022/Rust/src/day5.rs b/2022/Rust/src/day5.rs index 12ff7a8..d344ddd 100644 --- a/2022/Rust/src/day5.rs +++ b/2022/Rust/src/day5.rs @@ -73,17 +73,25 @@ impl FromStr for Command { fn apply_command(stacks: &mut Vec, cmd: &Command, part1: bool) { if part1 { for _ in 0..cmd.num_of_times { - let element_to_push = stacks[cmd.from - 1].stack.pop_back().expect("welp the stack is empty"); + let element_to_push = stacks[cmd.from - 1] + .stack + .pop_back() + .expect("welp the stack is empty"); stacks[cmd.target - 1].stack.push_back(element_to_push); } } else { - let mut tmp_stack :VecDeque = VecDeque::new(); + let mut tmp_stack: VecDeque = VecDeque::new(); for _ in 0..cmd.num_of_times { - let element_to_push = stacks[cmd.from - 1].stack.pop_back().expect("welp the stack is empty"); + let element_to_push = stacks[cmd.from - 1] + .stack + .pop_back() + .expect("welp the stack is empty"); tmp_stack.push_back(element_to_push); } for _ in 0..cmd.num_of_times { - stacks[cmd.target - 1].stack.push_back(tmp_stack.pop_back().unwrap()); + stacks[cmd.target - 1] + .stack + .push_back(tmp_stack.pop_back().unwrap()); } } } -- cgit v1.2.3