optimization
This commit is contained in:
parent
467387618b
commit
eebed65b33
@ -10,19 +10,16 @@ my $spiral = Array::Tour::Spiral->new( dimensions => $num );
|
|||||||
|
|
||||||
my $grid = [];
|
my $grid = [];
|
||||||
my $first = 1;
|
my $first = 1;
|
||||||
|
my $current = 0;
|
||||||
|
|
||||||
while ( my ($x,$y) = $spiral->next->@* ) {
|
until ( $current > $num ) {
|
||||||
if( $first) {
|
my ($x,$y) = $spiral->next->@*;
|
||||||
$grid->[$x][$y] = 1;
|
$current = $grid->[$x][$y] =
|
||||||
$first = 0;
|
$first ? $first--
|
||||||
}
|
: sum map {
|
||||||
else {
|
|
||||||
$grid->[$x][$y] = sum map {
|
|
||||||
my $i = $_;
|
my $i = $_;
|
||||||
map { $grid->[$x+$i][$y+$_] } -1..1
|
map { $grid->[$x+$i][$y+$_] } -1..1
|
||||||
} -1..1
|
} -1..1
|
||||||
}
|
|
||||||
|
|
||||||
warn $grid->[$x][$y];
|
|
||||||
exit say $_ for grep { $_ > $num } $grid->[$x][$y];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
say $current;
|
||||||
|
Loading…
Reference in New Issue
Block a user