File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Solution to Project Euler’s http://projecteuler.net/problem=28
2
+ # by Shlomi Fish
3
+
4
+ = begin pod
5
+
6
+ = head1 DESCRIPTION
7
+
8
+ Starting with the number 1 and moving to the right in a clockwise direction a 5
9
+ by 5 spiral is formed as follows:
10
+
11
+ 21 22 23 24 25
12
+ 20 7 8 9 10
13
+ 19 6 1 2 11
14
+ 18 5 4 3 12
15
+ 17 16 15 14 13
16
+
17
+ It can be verified that the sum of the numbers on the diagonals is 101.
18
+
19
+ What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed
20
+ in the same way?
21
+
22
+ = end pod
23
+
24
+ use v6 ;
25
+
26
+ my Int $ sum = 0 ;
27
+
28
+ my Int $ num = 1 ;
29
+
30
+ $ sum += $ num ;
31
+
32
+ for 2 , 4 ... 1000 -> $ step
33
+ {
34
+ for 0 .. 3
35
+ {
36
+ $ num += $ step ;
37
+ $ sum += $ num ;
38
+ }
39
+ }
40
+ print " Sum = $ sum\n " ;
You can’t perform that action at this time.
0 commit comments