2021: day03: use Vec::retain

~30% improvement in benchmark!
This commit is contained in:
Antoine Martin 2021-12-04 15:45:57 +01:00
parent 66fa27de0b
commit a5adc0185e

View file

@ -93,15 +93,7 @@ where
let one_is_more_common = count_ones(&numbers, pos) >= ((numbers.len() + 1) / 2);
let digit_of_interest = strat(one_is_more_common);
// TODO: use drain_filter when stable
let mut i = 0;
while i < numbers.len() {
if numbers[i].chars().nth(pos).unwrap() != digit_of_interest {
numbers.remove(i);
} else {
i += 1;
}
}
numbers.retain(|number| number.chars().nth(pos).unwrap() == digit_of_interest);
}
debug_assert_eq!(numbers.len(), 1);