2021: day03: use Vec::retain
~30% improvement in benchmark!
This commit is contained in:
parent
66fa27de0b
commit
a5adc0185e
|
@ -93,15 +93,7 @@ where
|
||||||
let one_is_more_common = count_ones(&numbers, pos) >= ((numbers.len() + 1) / 2);
|
let one_is_more_common = count_ones(&numbers, pos) >= ((numbers.len() + 1) / 2);
|
||||||
let digit_of_interest = strat(one_is_more_common);
|
let digit_of_interest = strat(one_is_more_common);
|
||||||
|
|
||||||
// TODO: use drain_filter when stable
|
numbers.retain(|number| number.chars().nth(pos).unwrap() == digit_of_interest);
|
||||||
let mut i = 0;
|
|
||||||
while i < numbers.len() {
|
|
||||||
if numbers[i].chars().nth(pos).unwrap() != digit_of_interest {
|
|
||||||
numbers.remove(i);
|
|
||||||
} else {
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_assert_eq!(numbers.len(), 1);
|
debug_assert_eq!(numbers.len(), 1);
|
||||||
|
|
Loading…
Reference in a new issue