diff --git a/project_euler/problem_06/sol1.py b/project_euler/problem_06/sol1.py index d6506ea28..38f995bbf 100644 --- a/project_euler/problem_06/sol1.py +++ b/project_euler/problem_06/sol1.py @@ -1,5 +1,5 @@ """ -Problem: +Problem 6: https://projecteuler.net/problem=6 The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 @@ -15,7 +15,7 @@ numbers and the square of the sum. """ -def solution(n: int) -> int: +def solution(n: int = 100) -> int: """Returns the difference between the sum of the squares of the first n natural numbers and the square of the sum. @@ -27,6 +27,8 @@ def solution(n: int) -> int: 41230 >>> solution(50) 1582700 + >>> solution() + 25164150 """ sum_of_squares = 0 sum_of_ints = 0 diff --git a/project_euler/problem_06/sol2.py b/project_euler/problem_06/sol2.py index 5032775f9..f4d74c993 100644 --- a/project_euler/problem_06/sol2.py +++ b/project_euler/problem_06/sol2.py @@ -1,5 +1,5 @@ """ -Problem: +Problem 6: https://projecteuler.net/problem=6 The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 @@ -15,7 +15,7 @@ numbers and the square of the sum. """ -def solution(n: int) -> int: +def solution(n: int = 100) -> int: """Returns the difference between the sum of the squares of the first n natural numbers and the square of the sum. @@ -27,6 +27,8 @@ def solution(n: int) -> int: 41230 >>> solution(50) 1582700 + >>> solution() + 25164150 """ sum_cubes = (n * (n + 1) // 2) ** 2 sum_squares = n * (n + 1) * (2 * n + 1) // 6 diff --git a/project_euler/problem_06/sol3.py b/project_euler/problem_06/sol3.py index 385ad0515..8b5c5d3ba 100644 --- a/project_euler/problem_06/sol3.py +++ b/project_euler/problem_06/sol3.py @@ -1,5 +1,5 @@ """ -Problem: +Problem 6: https://projecteuler.net/problem=6 The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 @@ -16,7 +16,7 @@ numbers and the square of the sum. import math -def solution(n: int) -> int: +def solution(n: int = 100) -> int: """Returns the difference between the sum of the squares of the first n natural numbers and the square of the sum. @@ -28,6 +28,8 @@ def solution(n: int) -> int: 41230 >>> solution(50) 1582700 + >>> solution() + 25164150 """ sum_of_squares = sum([i * i for i in range(1, n + 1)]) square_of_sum = int(math.pow(sum(range(1, n + 1)), 2)) diff --git a/project_euler/problem_06/sol4.py b/project_euler/problem_06/sol4.py index 912a3e8f6..5fae84008 100644 --- a/project_euler/problem_06/sol4.py +++ b/project_euler/problem_06/sol4.py @@ -1,5 +1,5 @@ """ -Problem: +Problem 6: https://projecteuler.net/problem=6 The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385 @@ -15,7 +15,7 @@ numbers and the square of the sum. """ -def solution(n: int) -> int: +def solution(n: int = 100) -> int: """Returns the difference between the sum of the squares of the first n natural numbers and the square of the sum. @@ -27,7 +27,7 @@ def solution(n: int) -> int: 41230 >>> solution(50) 1582700 - >>> solution(100) + >>> solution() 25164150 """ sum_of_squares = n * (n + 1) * (2 * n + 1) / 6 diff --git a/project_euler/problem_06/test_solutions.py b/project_euler/problem_06/test_solutions.py deleted file mode 100644 index 6d5337789..000000000 --- a/project_euler/problem_06/test_solutions.py +++ /dev/null @@ -1,18 +0,0 @@ -from .sol1 import solution as sol1 -from .sol2 import solution as sol2 -from .sol3 import solution as sol3 -from .sol4 import solution as sol4 - - -def test_solutions() -> None: - """ - >>> test_solutions() - """ - assert sol1(10) == sol2(10) == sol3(10) == sol4(10) == 2640 - assert sol1(15) == sol2(15) == sol3(15) == sol4(15) == 13160 - assert sol1(20) == sol2(20) == sol3(20) == sol4(20) == 41230 - assert sol1(50) == sol2(50) == sol3(50) == sol4(50) == 1582700 - - -if __name__ == "__main__": - test_solutions()