Skip to content

Add default arguments for Project Euler problem 6 #2957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions project_euler/problem_06/sol1.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +15,7 @@
"""


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.

Expand All @@ -27,6 +27,8 @@ def solution(n: int) -> int:
41230
>>> solution(50)
1582700
>>> solution()
25164150
"""
sum_of_squares = 0
sum_of_ints = 0
Expand Down
6 changes: 4 additions & 2 deletions project_euler/problem_06/sol2.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +15,7 @@
"""


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.

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions project_euler/problem_06/sol3.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@
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.

Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions project_euler/problem_06/sol4.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +15,7 @@
"""


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.

Expand All @@ -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
Expand Down
18 changes: 0 additions & 18 deletions project_euler/problem_06/test_solutions.py

This file was deleted.