Skip to content

Commit 1bcf110

Browse files
authored
Cleanup Project Euler Problem 01 (TheAlgorithms#2900)
* mv str statement into docstr * rename var to avoid redefining builtin * clean up module docstr
1 parent cc7405e commit 1bcf110

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

Diff for: project_euler/problem_01/sol1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

Diff for: project_euler/problem_01/sol2.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

@@ -19,14 +19,14 @@ def solution(n: int = 1000) -> int:
1919
83700
2020
"""
2121

22-
sum = 0
22+
total = 0
2323
terms = (n - 1) // 3
24-
sum += ((terms) * (6 + (terms - 1) * 3)) // 2 # sum of an A.P.
24+
total += ((terms) * (6 + (terms - 1) * 3)) // 2 # total of an A.P.
2525
terms = (n - 1) // 5
26-
sum += ((terms) * (10 + (terms - 1) * 5)) // 2
26+
total += ((terms) * (10 + (terms - 1) * 5)) // 2
2727
terms = (n - 1) // 15
28-
sum -= ((terms) * (30 + (terms - 1) * 15)) // 2
29-
return sum
28+
total -= ((terms) * (30 + (terms - 1) * 15)) // 2
29+
return total
3030

3131

3232
if __name__ == "__main__":

Diff for: project_euler/problem_01/sol3.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

@@ -22,38 +22,38 @@ def solution(n: int = 1000) -> int:
2222
83700
2323
"""
2424

25-
sum = 0
25+
total = 0
2626
num = 0
2727
while 1:
2828
num += 3
2929
if num >= n:
3030
break
31-
sum += num
31+
total += num
3232
num += 2
3333
if num >= n:
3434
break
35-
sum += num
35+
total += num
3636
num += 1
3737
if num >= n:
3838
break
39-
sum += num
39+
total += num
4040
num += 3
4141
if num >= n:
4242
break
43-
sum += num
43+
total += num
4444
num += 1
4545
if num >= n:
4646
break
47-
sum += num
47+
total += num
4848
num += 2
4949
if num >= n:
5050
break
51-
sum += num
51+
total += num
5252
num += 3
5353
if num >= n:
5454
break
55-
sum += num
56-
return sum
55+
total += num
56+
return total
5757

5858

5959
if __name__ == "__main__":

Diff for: project_euler/problem_01/sol4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

Diff for: project_euler/problem_01/sol5.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

8-
"""A straightforward pythonic solution using list comprehension"""
9-
108

119
def solution(n: int = 1000) -> int:
1210
"""Returns the sum of all the multiples of 3 or 5 below n.
11+
A straightforward pythonic solution using list comprehension.
1312
1413
>>> solution(3)
1514
0

Diff for: project_euler/problem_01/sol6.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

Diff for: project_euler/problem_01/sol7.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Problem Statement:
33
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4-
we get 3,5,6 and 9. The sum of these multiples is 23.
4+
we get 3, 5, 6 and 9. The sum of these multiples is 23.
55
Find the sum of all the multiples of 3 or 5 below N.
66
"""
77

0 commit comments

Comments
 (0)