Skip to content

Commit 5f415ce

Browse files
committed
[Euler] Add solution for Euler #28.
1 parent 83651e5 commit 5f415ce

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

euler/prob028-shlomif.pl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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";

0 commit comments

Comments
 (0)