File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
+ Problem 28
3
+ Url: https://projecteuler.net/problem=28
4
+ Statement:
2
5
Starting with the number 1 and moving to the right in a clockwise direction a 5
3
6
by 5 spiral is formed as follows:
4
7
17
20
from math import ceil
18
21
19
22
20
- def diagonal_sum ( n ) :
23
+ def solution ( n : int = 1001 ) -> int :
21
24
"""Returns the sum of the numbers on the diagonals in a n by n spiral
22
25
formed in the same way.
23
26
24
- >>> diagonal_sum (1001)
27
+ >>> solution (1001)
25
28
669171001
26
- >>> diagonal_sum (500)
29
+ >>> solution (500)
27
30
82959497
28
- >>> diagonal_sum (100)
31
+ >>> solution (100)
29
32
651897
30
- >>> diagonal_sum (50)
33
+ >>> solution (50)
31
34
79697
32
- >>> diagonal_sum (10)
35
+ >>> solution (10)
33
36
537
34
37
"""
35
38
total = 1
@@ -46,10 +49,10 @@ def diagonal_sum(n):
46
49
import sys
47
50
48
51
if len (sys .argv ) == 1 :
49
- print (diagonal_sum ( 1001 ))
52
+ print (solution ( ))
50
53
else :
51
54
try :
52
55
n = int (sys .argv [1 ])
53
- print (diagonal_sum (n ))
56
+ print (solution (n ))
54
57
except ValueError :
55
58
print ("Invalid entry - please enter a number" )
You can’t perform that action at this time.
0 commit comments