Skip to content

Commit 5b0a113

Browse files
authored
Add default arguments for Project Euler problem 6 (TheAlgorithms#2957)
- Add default arguments to solution function - Add link to Project Euler problem 6 - Add doctest for testing `solution()` - Removed test_solutions.py as it is redundant
1 parent 7084994 commit 5b0a113

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

Diff for: project_euler/problem_06/sol1.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Problem:
2+
Problem 6: https://projecteuler.net/problem=6
33
44
The sum of the squares of the first ten natural numbers is,
55
1^2 + 2^2 + ... + 10^2 = 385
@@ -15,7 +15,7 @@
1515
"""
1616

1717

18-
def solution(n: int) -> int:
18+
def solution(n: int = 100) -> int:
1919
"""Returns the difference between the sum of the squares of the first n
2020
natural numbers and the square of the sum.
2121
@@ -27,6 +27,8 @@ def solution(n: int) -> int:
2727
41230
2828
>>> solution(50)
2929
1582700
30+
>>> solution()
31+
25164150
3032
"""
3133
sum_of_squares = 0
3234
sum_of_ints = 0

Diff for: project_euler/problem_06/sol2.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Problem:
2+
Problem 6: https://projecteuler.net/problem=6
33
44
The sum of the squares of the first ten natural numbers is,
55
1^2 + 2^2 + ... + 10^2 = 385
@@ -15,7 +15,7 @@
1515
"""
1616

1717

18-
def solution(n: int) -> int:
18+
def solution(n: int = 100) -> int:
1919
"""Returns the difference between the sum of the squares of the first n
2020
natural numbers and the square of the sum.
2121
@@ -27,6 +27,8 @@ def solution(n: int) -> int:
2727
41230
2828
>>> solution(50)
2929
1582700
30+
>>> solution()
31+
25164150
3032
"""
3133
sum_cubes = (n * (n + 1) // 2) ** 2
3234
sum_squares = n * (n + 1) * (2 * n + 1) // 6

Diff for: project_euler/problem_06/sol3.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Problem:
2+
Problem 6: https://projecteuler.net/problem=6
33
44
The sum of the squares of the first ten natural numbers is,
55
1^2 + 2^2 + ... + 10^2 = 385
@@ -16,7 +16,7 @@
1616
import math
1717

1818

19-
def solution(n: int) -> int:
19+
def solution(n: int = 100) -> int:
2020
"""Returns the difference between the sum of the squares of the first n
2121
natural numbers and the square of the sum.
2222
@@ -28,6 +28,8 @@ def solution(n: int) -> int:
2828
41230
2929
>>> solution(50)
3030
1582700
31+
>>> solution()
32+
25164150
3133
"""
3234
sum_of_squares = sum([i * i for i in range(1, n + 1)])
3335
square_of_sum = int(math.pow(sum(range(1, n + 1)), 2))

Diff for: project_euler/problem_06/sol4.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Problem:
2+
Problem 6: https://projecteuler.net/problem=6
33
44
The sum of the squares of the first ten natural numbers is,
55
1^2 + 2^2 + ... + 10^2 = 385
@@ -15,7 +15,7 @@
1515
"""
1616

1717

18-
def solution(n: int) -> int:
18+
def solution(n: int = 100) -> int:
1919
"""Returns the difference between the sum of the squares of the first n
2020
natural numbers and the square of the sum.
2121
@@ -27,7 +27,7 @@ def solution(n: int) -> int:
2727
41230
2828
>>> solution(50)
2929
1582700
30-
>>> solution(100)
30+
>>> solution()
3131
25164150
3232
"""
3333
sum_of_squares = n * (n + 1) * (2 * n + 1) / 6

Diff for: project_euler/problem_06/test_solutions.py

-18
This file was deleted.

0 commit comments

Comments
 (0)