Uh oh!
There was an error while loading. Please reload this page.
Unify O(sqrt(N))is_prime functions under project_euler - #6258
Conversation
I think it is better to remove the assertion in all together since it doesn't have actual value for the implementation of the primality test algorithm and maybe it is a bit of confusing even. Should I do that? @poyea Edit: For example in project_euler/problem_003/sol1.py lines 41-43. |
poyea
commented
Jul 20, 2022
@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_eulerO(sqrt(N))is_prime under project_eulerO(sqrt(N))is_prime functions under project_euler
poyea
left a comment
There was a problem hiding this comment.
Thank you for your pull request!🤩
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: John Law <johnlaw.po@gmail.com>
ngiachou
commented
Aug 18, 2022
@poyea Is there any other changes I should make? |
poyea
left a comment
There was a problem hiding this comment.
It's been a while and this looks good to me. 👍
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