{{ message }}
Unify O(sqrt(N)) is_prime functions under project_euler - #6258
Merged
poyea merged 6 commits intoSep 14, 2022
Merged
Conversation
Contributor
Author
Member
|
@elpaxoudis Yeah, I think they can be removed, and the negative / type check can be performed when processing input (if any). If we want to handle the negative / type check in the function, I think it makes sense to raise an exception / an assertion failure, instead of return |
is_prime under project_eulerO(sqrt(N)) is_prime under project_euler
O(sqrt(N)) is_prime under project_eulerO(sqrt(N)) is_prime functions under project_euler
poyea
approved these changes
Jul 27, 2022
poyea
left a comment
Member
There was a problem hiding this comment.
Thank you for your pull request!🤩
Co-authored-by: John Law <johnlaw.po@gmail.com>
Contributor
Author
poyea
approved these changes
Sep 14, 2022
poyea
left a comment
Member
There was a problem hiding this comment.
It's been a while and this looks good to me. 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Describe your change:
I changed the implementation of is_prime functions inside project_euler in order to have a unified implementation. There are some cases where the solution uses the Eratosthenes' sieve method. In some cases there is no specific gain from using that method so I changed it to the O(sqrt(n)) algorithm, but in other cases the sieve method is used in the core structure of the solution, hence I did not touch those.
Checklist:
Fixes: #{$ISSUE_NO}.fixes #5434