I am writing a sieve of Eratosthenes, for this you want to start a vector of booleans with odd indices true
and even indices false
. Currently my code for getting that is:
let mut is_prime: Vec<bool> = vec![true; capacity];
is_prime.iter_mut().step_by(2).for_each(|m| *m = false);
However, I am trying to find a way of constructing the vector with this alternating true
false
sequence. Any help is appreciated, thanks.
Note
I know this won't have a massive impact on performance in this case, I but I thought it was an interesting problem and suspect there may be cases where it would make a difference.