- Notifications
You must be signed in to change notification settings - Fork25
Added algorithm to compute prime numbers less than x#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
dc4137a Added algorithm to compute prime numbers less than x
b6d4bb0 Added docs, test and format for code
c95441f Renaming numeric to math
abranhea7b2a25 Update and rename allalgorithms/numeric/prime_numbers.py to allalgori…
abranhe4d63f53 Update and rename test_numeric.py to test_math.py
abranhe6be290f Update and rename allalgorithms/numeric/__init__.py to allalgorithms/…
abranheFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsallalgorithms/math/__init__.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .max_numbers import find_max |
31 changes: 31 additions & 0 deletionsallalgorithms/math/prime_numbers.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # -*- coding: UTF-8 -*- | ||
| # | ||
| # Numeric Algorithms | ||
| # The All ▲lgorithms library for python | ||
| # | ||
| # Contributed by: Rodolfo | ||
| # Github: @RQuispeC | ||
| # | ||
| import math | ||
| SIEVE_LIMIT = 1000000 | ||
| def sieve(n): | ||
| prime = [True]*(n+1) | ||
| prime[0] = False | ||
| prime[1] = False | ||
| for i in range(2,int(math.sqrt(n)) + 1): | ||
| if prime[i]: | ||
| for j in range(i*i, n+1, i): | ||
| prime[j] = False | ||
| return prime | ||
| def prime_lower(n): | ||
| if n < 1 or n > SIEVE_LIMIT: | ||
| return [] | ||
| prime = sieve(n) | ||
| ans = [] | ||
| for i in range(n+1): | ||
| if prime[i]: | ||
| ans.append(i) | ||
| return ans |
1 change: 0 additions & 1 deletionallalgorithms/numeric/__init__.py
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
34 changes: 34 additions & 0 deletionsdocs/math/prime-numbers.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Prime Numbers | ||
| Using prime numbers is common in many problems. We implement various algorithms using them. | ||
| ## Install | ||
| ``` | ||
| pip install allalgorithms | ||
| ``` | ||
| ## Usage | ||
| ```py | ||
| from allalgorithms.math import prime_lower | ||
| print(prime_lower(18)) | ||
| # -> [2, 3, 5, 7, 11, 13, 17] | ||
| print(prime_lower(-1)) | ||
| # -> [] | ||
| print(prime_lower(1000001)) | ||
| # -> [] | ||
| ``` | ||
| ## API | ||
| ### prime_lower(query) | ||
| > Return array of prime numbers lower than `query`, `query` must be lower than `10e6` to avoid memory problems. | ||
| ##### Params: | ||
| - `query`: superior limit for the array of prime number |
5 changes: 3 additions & 2 deletionstests/test_numeric.py → tests/test_math.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import unittest | ||
| from allalgorithms.math import ( | ||
| find_max | ||
| ) | ||
| class TestMax(unittest.TestCase): | ||
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.