-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Prime numbers: Added description, removed unnecessary implementation, and improved current #5048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…he current implementation by incrementing by 2 instead of 1
>>> list(primes(0)) | ||
[] | ||
>>> list(primes(-1)) | ||
[] | ||
>>> list(primes(-10)) | ||
[] | ||
>>> list(primes(25)) | ||
[2, 3, 5, 7, 11, 13, 17, 19, 23] | ||
>>> list(primes(11)) | ||
[2, 3, 5, 7, 11] | ||
>>> list(primes(33)) | ||
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] | ||
>>> list(primes(10000))[-1] | ||
9973 | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and keep the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests dont make sense since we removed one of the functions, it just compared the two timings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (i % j) == 0: | ||
break | ||
else: | ||
yield i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these brackets
""" | ||
Naive implementation of finding primes by checking if each number | ||
is divisible by 2 or any odd number up to its root. | ||
|
||
For a fast implementation see Sieve of Eratosthenes. | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok to keep an explanation, but state that there are two impls, and you can compre both.
Describe your change:
Added description, removed unnecessary implementation, and improved the current implementation by incrementing by 2 instead of 1. I kept the name slow_primes around to emphazise that this is not a very good method of finding primes. This is also apparent from the description
Checklist:
Fixes: #{$ISSUE_NO}
.