Added day 5 part 2
This commit is contained in:
parent
fbdcc46626
commit
e2e9d95a16
13
src/main.rs
13
src/main.rs
|
@ -93,16 +93,21 @@ fn main() {
|
||||||
|
|
||||||
fn solution(mut input: Stack) -> String {
|
fn solution(mut input: Stack) -> String {
|
||||||
for ins in input.instructions {
|
for ins in input.instructions {
|
||||||
for _ in 0..ins.count {
|
let l = input.stacks[ins.from - 1].len();
|
||||||
if let Some(v) = input.stacks[ins.from - 1].pop() {
|
|
||||||
input.stacks[ins.to - 1].push(v);
|
let crates: Vec<char> = input.stacks[ins.from - 1]
|
||||||
}
|
.drain(l.saturating_sub(ins.count)..l)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for c in crates {
|
||||||
|
input.stacks[ins.to - 1].push(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input
|
input
|
||||||
.stacks
|
.stacks
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.filter(|c| !c.is_empty())
|
||||||
.map(|c| *c.last().unwrap())
|
.map(|c| *c.last().unwrap())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user