Skip to content

Commit 8fa2857

Browse files
authored
Merge pull request #6 from yourbasic/tip
Simplify example
2 parents 1965bb6 + ba28a67 commit 8fa2857

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

example_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ func Example_basics() {
3131
// Create the set of all primes less than n in O(n log log n) time.
3232
// Try the code with n equal to a few hundred millions and be pleasantly surprised.
3333
func Example_primes() {
34-
// Sieve of Eratosthenes (with optimization suggested by tege)
34+
// Sieve of Eratosthenes
3535
const n = 50
3636
sieve := bit.New().AddRange(2, n)
37-
for k := 4; k < n; k += 2 {
38-
sieve.Delete(k)
39-
}
4037
sqrtN := int(math.Sqrt(n))
41-
for p := 3; p <= sqrtN; p = sieve.Next(p) {
42-
for k := p * p; k < n; k += 2 * p {
38+
for p := 2; p <= sqrtN; p = sieve.Next(p) {
39+
for k := p * p; k < n; k += p {
4340
sieve.Delete(k)
4441
}
4542
}

0 commit comments

Comments
 (0)