diff --git a/src/bin/d5p2.rs b/src/bin/d5p2.rs new file mode 100644 index 0000000..57a703d --- /dev/null +++ b/src/bin/d5p2.rs @@ -0,0 +1,34 @@ +use std::collections::VecDeque; + +use aoc22::{day5, util}; + +pub fn main() { + let mut arrangement = day5::parse_arrangement(&util::parse_input()); + + for inst in &arrangement.instructions { + let mut boxes = VecDeque::new(); + for _ in 0..inst.num { + let box_ = arrangement + .stacks + .get_mut(inst.from) + .unwrap() + .pop_back() + .unwrap(); + boxes.push_front(box_); + } + + arrangement + .stacks + .get_mut(inst.to) + .unwrap() + .append(&mut boxes); + } + + let top_boxes: String = arrangement + .stacks + .iter() + .map(|s| s.iter().next_back().unwrap()) + .collect(); + + println!("The top boxes are {}", top_boxes); +}