1
0

Optimized day 5 part 2

This commit is contained in:
Ishan Jain 2022-12-05 17:35:07 +05:30
parent 384625e7a6
commit 12439c6ed7
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27

View File

@ -122,9 +122,7 @@ fn solution(mut input: Stack) -> String {
for ins in input.instructions { for ins in input.instructions {
let l = input.stacks[ins.from - 1].len(); let l = input.stacks[ins.from - 1].len();
let crates: Vec<u8> = input.stacks[ins.from - 1] let crates = input.stacks[ins.from - 1].split_off(l.saturating_sub(ins.count));
.drain(l.saturating_sub(ins.count)..l)
.collect();
input.stacks[ins.to - 1].extend(crates); input.stacks[ins.to - 1].extend(crates);
} }