Skip to content

Update code style for Project Euler Problem 28 #2976

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
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
19 changes: 11 additions & 8 deletions project_euler/problem_28/sol1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
Problem 28
Url: https://projecteuler.net/problem=28
Statement:
Starting with the number 1 and moving to the right in a clockwise direction a 5
by 5 spiral is formed as follows:

Expand All @@ -17,19 +20,19 @@
from math import ceil


def diagonal_sum(n):
def solution(n: int = 1001) -> int:
"""Returns the sum of the numbers on the diagonals in a n by n spiral
formed in the same way.

>>> diagonal_sum(1001)
>>> solution(1001)
669171001
>>> diagonal_sum(500)
>>> solution(500)
82959497
>>> diagonal_sum(100)
>>> solution(100)
651897
>>> diagonal_sum(50)
>>> solution(50)
79697
>>> diagonal_sum(10)
>>> solution(10)
537
"""
total = 1
Expand All @@ -46,10 +49,10 @@ def diagonal_sum(n):
import sys

if len(sys.argv) == 1:
print(diagonal_sum(1001))
print(solution())
else:
try:
n = int(sys.argv[1])
print(diagonal_sum(n))
print(solution(n))
except ValueError:
print("Invalid entry - please enter a number")