Skip to content

Commit d5ae2b0

Browse files
JasirZaeemstokhos
authored andcommitted
Update code style for Project Euler Problem 28 (TheAlgorithms#2976)
Add default arguments, typehints and rename solution function for Porject Euler Problem 28
1 parent b2aa99e commit d5ae2b0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: project_euler/problem_28/sol1.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""
2+
Problem 28
3+
Url: https://projecteuler.net/problem=28
4+
Statement:
25
Starting with the number 1 and moving to the right in a clockwise direction a 5
36
by 5 spiral is formed as follows:
47
@@ -17,19 +20,19 @@
1720
from math import ceil
1821

1922

20-
def diagonal_sum(n):
23+
def solution(n: int = 1001) -> int:
2124
"""Returns the sum of the numbers on the diagonals in a n by n spiral
2225
formed in the same way.
2326
24-
>>> diagonal_sum(1001)
27+
>>> solution(1001)
2528
669171001
26-
>>> diagonal_sum(500)
29+
>>> solution(500)
2730
82959497
28-
>>> diagonal_sum(100)
31+
>>> solution(100)
2932
651897
30-
>>> diagonal_sum(50)
33+
>>> solution(50)
3134
79697
32-
>>> diagonal_sum(10)
35+
>>> solution(10)
3336
537
3437
"""
3538
total = 1
@@ -46,10 +49,10 @@ def diagonal_sum(n):
4649
import sys
4750

4851
if len(sys.argv) == 1:
49-
print(diagonal_sum(1001))
52+
print(solution())
5053
else:
5154
try:
5255
n = int(sys.argv[1])
53-
print(diagonal_sum(n))
56+
print(solution(n))
5457
except ValueError:
5558
print("Invalid entry - please enter a number")

0 commit comments

Comments
 (0)