Day 5, puzzle 1
This commit is contained in:
25
src/bin/d5p1.rs
Normal file
25
src/bin/d5p1.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use aoc22::{day5, util};
|
||||
|
||||
pub fn main() {
|
||||
let mut arrangement = day5::parse_arrangement(&util::parse_input());
|
||||
|
||||
for inst in &arrangement.instructions {
|
||||
for _ in 0..inst.num {
|
||||
let box_ = arrangement
|
||||
.stacks
|
||||
.get_mut(inst.from)
|
||||
.unwrap()
|
||||
.pop_back()
|
||||
.unwrap();
|
||||
arrangement.stacks.get_mut(inst.to).unwrap().push_back(box_);
|
||||
}
|
||||
}
|
||||
|
||||
let top_boxes: String = arrangement
|
||||
.stacks
|
||||
.iter()
|
||||
.map(|s| s.iter().next_back().unwrap())
|
||||
.collect();
|
||||
|
||||
println!("The top boxes are {}", top_boxes);
|
||||
}
|
||||
Reference in New Issue
Block a user