From cc69036ae26a587aa9a79156029c90fe67f7069a Mon Sep 17 00:00:00 2001 From: drbaggy Date: Tue, 23 Feb 2021 05:10:43 +0000 Subject: tidied up initialiser --- challenge-101/james-smith/perl/ch-1.pl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/challenge-101/james-smith/perl/ch-1.pl b/challenge-101/james-smith/perl/ch-1.pl index 18434b2b69..b223880b14 100644 --- a/challenge-101/james-smith/perl/ch-1.pl +++ b/challenge-101/james-smith/perl/ch-1.pl @@ -15,16 +15,14 @@ sub print_spiral { } sub pack_spiral { - my $rows = 1; ## Get the value for columns & rows which have the smallest gap ## but still multiply to size of array (we choose rows to be ## no greater than columns as printing is neater - but for no ## other reason... - $rows = @_%$_ ? $rows : $_ foreach 2 .. sqrt @_; - - my ($cols,$r,$c,@out) = (@_/$rows,$rows-1,-1); + my( $rows ) = reverse grep { ! (@_ % $_) } 1 .. sqrt @_; + my( $cols, $r, $c, @out ) = ( @_/$rows, $rows-1, -1 ); ## We start bottom left... ## because we use pre-inc we actually start 1 to the left of it! -- cgit