in reply to Re: (golf) Triangle of numbers
in thread (golf) Triangle of numbers
$_ = ($a*($a+1))/2; # calculate last number in triangle my @arr = 1..$_; # list of all numbers in triangle my $i; while(@arr) { $i++; my $format = ' %' . y///c . 'd'; # y///c is a short version of lengt +h($_) # originally in "@{[2 + 2]}" form - +- which # creates, dereferences and stringi +fies # a one element array ref my @row = splice(@arr,0,$i); # take $i elements off the front of + @arr printf $format x $i . $/, @row; # print the whole row, instead of u +sing an # explicit loop like the rest of us }
-Blake
|
|---|