Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I really like this. I liked it even more as I worked through all of the examples to better understand them. One thing I would change:

    say $_.perl for @pascal;

    The output is much clearer that way (at least to me). I actually tried to get it a touch more "triangly":

    my @pascal := do [1], -> @p { [0,@p Z+ @p,0] } ... *;
    say ' ' x 2 * (10 - $_.elems), $_.perl for @pascal[^10];

    But wound up with this:

                      [1]
               

    • by masak (6289) on 2010.08.30 8:49 (#72360) Homepage Journal

      my $n = 10;
      my @pascal := do [1], -> @p { [0,@p Z+ @p,0] } ... *;
      my $m = @pascal[$n - 1].perl.chars;
      say (my $r = $_.perl).fmt("%{($m + $r.chars) div 2}s") for @pascal[^$n];

      Produces this:

                       [1]
                      [1, 1]
                    [1, 2, 1]
                   [1, 3, 3, 1]
                 [1, 4, 6, 4, 1]
               [1, 5, 10, 10, 5, 1]
             [1, 6, 15, 20, 15, 6, 1]
           [1, 7, 21, 35, 35, 21, 7, 1]
         [1, 8, 28, 56, 70, 56, 28, 8, 1]
      [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]