in reply to (golf) Triangle of numbers

Here's my program, assuming $a holds the number. It's 68 characters.
$_=@;=1..$a++*$a/2;printf" %@{[y///c]}d"x++$;.$/,splice@;,0,$;while@;

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: (golf) Triangle of numbers
by blakem (Monsignor) on Oct 26, 2001 at 12:39 UTC
    Thats some nice obfued golfing! I took a few minutes to understand and translate it:
    $_ = ($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