Adding a prime check function #13223
Closed
+29
−0
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:
Added a new function is_prime(n: int) -> bool that checks if a number is prime using the efficient 6k ± 1 optimization.
It raises a ValueError for inputs less than or equal to 1, includes type hints, and contains doctests to verify correctness.
I noticed there is an existing implementation of prime checking in the repo(maths/prime_check.py).
Please advise if I should merge my improvements into the existing function instead of adding a separate one.
Checklist: