Skip to content

Commit cee6125

Browse files
committed
Add test case and remove print() for the euler project problem 127 solution.
1 parent 2491095 commit cee6125

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Diff for: project_euler/problem_127/sol1.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- if gcd(a, b) = 1 then gcd(a, c) = 1 and gcd(b, c) = 1
99
- rad(a*b*c) = rad(a) * rad(b) * rad(c), for gcd(a, b) = 1
1010
- if a is even, b cannot b even for gcd(a, b) = 1 to be true.
11+
12+
>>> solution(1000)
13+
12523
1114
"""
1215

1316
from numpy import sqrt
@@ -18,6 +21,11 @@
1821
def generate_primes(n: int) -> list[bool]:
1922
"""
2023
Generates primes boolean array up to n.
24+
25+
>>> generate_primes(2)
26+
[False, False, True]
27+
>>> generate_primes(5)
28+
[False, False, True, True, False, True]
2129
"""
2230
primes = [True] * (n + 1)
2331
primes[0] = primes[1] = False
@@ -34,6 +42,11 @@ def rad(n: int, primes_list: list[int]) -> int:
3442
"""
3543
Calculated rad - product of unique prime factors for n, using prime numbers
3644
list primes_list.
45+
46+
>>> rad(1, [1])
47+
1
48+
>>> rad(12, [2, 3])
49+
6
3750
"""
3851
f = 1
3952
for p in primes_list:
@@ -48,6 +61,10 @@ def gcd(a: int, b: int) -> int:
4861
"""
4962
Calculates greatest common divisor of a and b.
5063
64+
>>> gcd(1, 10)
65+
1
66+
>>> gcd(14, 48)
67+
2
5168
"""
5269
while b:
5370
a, b = b, a % b
@@ -58,6 +75,10 @@ def solution(c_less: int = 120000) -> int:
5875
"""
5976
Calculates all primes, rads, and then loops over a, b checking the conditions.
6077
78+
>>> solution(10)
79+
9
80+
>>> solution(100)
81+
316
6182
"""
6283
primes_bool = generate_primes(c_less)
6384
primes_list = []
@@ -67,8 +88,6 @@ def solution(c_less: int = 120000) -> int:
6788

6889
rads = [1] * (c_less + 1)
6990
for i in range(c_less + 1):
70-
if i % 100 == 0:
71-
print("rads", i)
7291
rads[i] = rad(i, primes_list)
7392

7493
sum_c = 0

0 commit comments

Comments
 (0)