Python version assert fails on odd numbers #231
martin-niklasson
started this conversation in
Improvement suggestions
Replies: 2 comments
-
Why not just |
Beta Was this translation helpful? Give feedback.
0 replies
-
Check in a fix, I'll gladly accept! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Try:
sieve = prime_sieve(999999) # Calc the primes up to a million-1
Result:
assert(count == this.countPrimes()) AssertionError
The reason is that keyword int in Python doesn't do what a C++ programmer thinks:
this.rawbits = [True] * (int((this.sieveSize+1)/2))
Fix by:
from math import sqrt,floor # Used by the sieve
and
this.rawbits = [True] * (floor((this.sieveSize)/2))
Beta Was this translation helpful? Give feedback.
All reactions