Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6d4bb0

Browse files
author
Rodolfo Quispe
committed
Added docs, test and format for code
1 parentdc4137a commitb6d4bb0

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

‎allalgorithms/numeric/prime_numbers.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@ def sieve(n):
2121
returnprime
2222

2323
defprime_lower(n):
24-
"""
25-
inputs:
26-
n: integer
27-
28-
outputs: list of prime numbers less or equal than n
29-
"""
30-
assertn>=1andn<=SIEVE_LIMIT,"input value is not valid"
24+
ifn<1orn>SIEVE_LIMIT:
25+
return []
3126
prime=sieve(n)
3227
ans= []
3328
foriinrange(n+1):

‎docs/numeric/prime-numbers.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Prime Numbers
2+
3+
Using prime numbers is common in many problems. We implement various algorithms using them.
4+
5+
##Install
6+
7+
```
8+
pip install allalgorithms
9+
```
10+
11+
##Usage
12+
13+
```py
14+
from allalgorithms.numericimport prime_lower
15+
16+
print(prime_lower(18))
17+
# -> [2, 3, 5, 7, 11, 13, 17]
18+
19+
print(prime_lower(-1))
20+
# -> []
21+
22+
print(prime_lower(1000001))
23+
# -> []
24+
```
25+
26+
##API
27+
28+
###prime_lower(query)
29+
30+
>Return array of prime numbers lower than`query`,`query` must be lower than`10e6` to avoid memory problems.
31+
32+
#####Params:
33+
34+
-`query`: superior limit for the array of prime number

‎tests/test_numeric.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
importunittest
22

3-
fromallalgorithms.numericimportfind_max
4-
3+
fromallalgorithms.numericimport (
4+
find_max,
5+
prime_lower
6+
)
57

68
classTestMax(unittest.TestCase):
79

810
deftest_find_max_value(self):
911
test_list= [3,1,8,7,4]
1012
self.assertEqual(8,find_max(test_list))
1113

14+
classTestPrimeLower(unittest.TestCase):
15+
16+
deftest_prime_lower_value(self):
17+
test_list=[2,3,5,7,11,13,17]
18+
self.assertEqual(prime_lower(18),test_list)
19+
20+
1221
if__name__=="__main__":
1322
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp