Skip to content

Commit

Permalink
In sieve example, end iteration sooner
Browse files Browse the repository at this point in the history
The Sieve algorithm only requires checking all elements up to and including the square root of the maximum prime you're looking for. After that, the remaining elements are guaranteed to be prime.
  • Loading branch information
gmfawcett committed Oct 9, 2014
1 parent e6cfb56 commit 7cf1f55
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! bv.set(0, false);
//! bv.set(1, false);
//!
//! for i in range(2, max_prime) {
//! for i in iter::range_inclusive(2, (max_prime as f64).sqrt() as uint) {
//! // if i is a prime
//! if bv[i] {
//! // Mark all multiples of i as non-prime (any multiples below i * i
Expand Down

0 comments on commit 7cf1f55

Please sign in to comment.