Day 5, puzzle 2
This commit is contained in:
parent
a4299a1fc5
commit
0506dc670a
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue