Update code style for Project Euler Problem 28 (#2976)

Add default arguments, typehints and rename solution function for Porject Euler Problem 28
This commit is contained in:
JasirZaeem 2020-10-07 18:35:06 +05:30 committed by GitHub
parent c510a7da7b
commit 05616ca38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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:
@ -17,19 +20,19 @@ in the same way?
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
@ -46,10 +49,10 @@ if __name__ == "__main__":
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")