Python: Deduplicate repeated `is_prime` functions
We have a lot of is_prime
(or similar) functions: https://github.com/TheAlgorithms/Python/search?p=4&q=is_prime, https://github.com/TheAlgorithms/Python/search?q=isPrime, data_structures/hashing/number_theory/prime_numbers, etc. Shall we use one common function for that exactly identical is_prime
calculation (which takes O(sqrt(n))
)?
Candidates include:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 46 (22 by maintainers)
Commits related to this issue
- Fixes (#5434) * Update ciphers.rabin_miller.py maths.miller_rabin.py — committed to paulosgf/Python by paulosgf 3 years ago
- Remove duplicate is_prime related functions (#5892) * Fixes (#5434) * Update ciphers.rabin_miller.py maths.miller_rabin.py * Fixing ERROR maths/miller_rabin.py - ModuleNotFoundError a... — committed to TheAlgorithms/Python by paulosgf 2 years ago
- fixes #5434 — committed to ngiachou/TheAlgorithmsPython by ngiachou 2 years ago
- Unify `O(sqrt(N))` `is_prime` functions under `project_euler` (#6258) * fixes #5434 * fixes broken solution * removes assert * removes assert * Apply suggestions from code review Co-au... — committed to TheAlgorithms/Python by ngiachou 2 years ago
Can you assign this to me.
I will do it!
@elpaxoudis That sounds good to me 😃 - unless there’s some weird specifications in the problem / custom implementation (say the author wrote a Sieve-like approach) which I’m sure it’s rare. Doctests / test cases are always welcome!
Hey @elpaxoudis! For 1 & 2, yes, and these can be done altogether in this issue. It would be of help if you could check also other algorithms and files in this repository which define a
is_prime
function or alike.For 3, I agree that one of them is a duplicate. Let’s handle it in a different issue (or without an issue because it’s straightforward in terms of scale of change). We can merge all the test cases / comments, while preserving one clearer version.
is_prime function to check whether a given number is prime using O(sqrt N) algorithm
I wanted to learn Python, but it seems to be a difficult language.
@poyea,
This is a list from Project Euler with
isprime()
like functions on his solutions:It’s to register for later decision.
Can I try solve this prob?
Hi! I’m interested in working on this