Day 5, puzzle 1

This commit is contained in:
jazzpi
2022-12-13 16:38:31 +01:00
parent d1a30ea629
commit a4299a1fc5
3 changed files with 123 additions and 0 deletions

25
src/bin/d5p1.rs Normal file
View 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);
}