{{ message }}
Fix: deduplicated "is_prime" functions - #5488
Closed
murilo-goncalves wants to merge 1 commit into
Closed
murilo-goncalves wants to merge 1 commit into
murilo-goncalves wants to merge 1 commit into
Conversation
murilo-goncalves
requested review from
Kush1101 and
dhruvmanila
as code owners
October 20, 2021 20:06
Contributor
Author
Member
|
poyea
reviewed
Oct 21, 2021
Comment on lines
7
to
11
| def prime_check(number: int) -> bool: | ||
| """Checks to see if a number is a prime. | ||
| """Checks to see if a number is a prime in O(sqrt(n)). | ||
|
|
||
| A number is prime if it has exactly two factors: 1 and itself. | ||
| """ |
Member
There was a problem hiding this comment.
We need to add a few tests to this function (although we have tests down there, we can still add a few doctests).
poyea
reviewed
Oct 21, 2021
| isPrime(number) | ||
| sieveEr(N) | ||
| getPrimeNumbers(N) | ||
| primeFactorization(number) |
Member
There was a problem hiding this comment.
Let's change these signatures too, e.g. sieve_of_eratosthenes
poyea
reviewed
Oct 21, 2021
Comment on lines
-17
to
-36
| """ | ||
| Returns boolean representing primality of given number num. | ||
|
|
||
| >>> isprime(2) | ||
| True | ||
| >>> isprime(3) | ||
| True | ||
| >>> isprime(27) | ||
| False | ||
| >>> isprime(2999) | ||
| True | ||
| >>> isprime(0) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Parameter num must be greater than or equal to two. | ||
| >>> isprime(1) | ||
| Traceback (most recent call last): | ||
| ... | ||
| ValueError: Parameter num must be greater than or equal to two. | ||
| """ |
Member
There was a problem hiding this comment.
Let's just copy-paste these to the prime check
poyea
reviewed
Oct 21, 2021
Comment on lines
-22
to
-30
| >>> is_prime(2) | ||
| True | ||
| >>> is_prime(15) | ||
| False | ||
| >>> is_prime(29) | ||
| True | ||
| >>> is_prime(0) | ||
| False | ||
| """ |
poyea
reviewed
Oct 21, 2021
Comment on lines
-20
to
-26
| >>> isprime(2) | ||
| True | ||
| >>> isprime(15) | ||
| False | ||
| >>> isprime(29) | ||
| True | ||
| """ |
poyea
reviewed
Oct 21, 2021
Comment on lines
-21
to
-29
| >>> is_prime(2) | ||
| True | ||
| >>> is_prime(3) | ||
| True | ||
| >>> is_prime(27) | ||
| False | ||
| >>> is_prime(2999) | ||
| True | ||
| """ |
poyea
reviewed
Oct 21, 2021
Comment on lines
-22
to
-30
| >>> is_prime(2) | ||
| True | ||
| >>> is_prime(3) | ||
| True | ||
| >>> is_prime(27) | ||
| False | ||
| >>> is_prime(2999) | ||
| True | ||
| """ |
poyea
reviewed
Oct 21, 2021
Comment on lines
-23
to
-29
| >>> is_prime(67483) | ||
| False | ||
| >>> is_prime(563) | ||
| True | ||
| >>> is_prime(87) | ||
| False | ||
| """ |
Member
|
It's probably |
Member
|
In Python 3.10 so it's causing errors: https://github.com/TheAlgorithms/Python/runs/3958162685?check_suite_focus=true#step:3:5 |
Member
|
Please see and wait for #5496. |
Contributor
Author
14 tasks
14 tasks
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.


Unified all functions that check if number is prime to maths/check_prime.py check_prime function, that checks primality in O(sqrt(n)).
Functions left unchanged:
Fixes: #5434
Checklist:
Fixes: #{$ISSUE_NO}.