in reply to Equilateral Pascal's Triangle in perltex
Pascal's Triangle. It has a couple of interactive versions that'll help you visualize what's going on.
Update: I've been looking for a couple of hours, just to satisfy my curiosity, and I finally found it. See Tie::Math under the "How about Pascal's Triangle" section:
#!/usr/bin/perl use Tie::Math qw(f X Y); my %pascal; tie %pascal, 'Tie::Math', sub { if( X <= Y and Y > 0 and X > 0 ) { f(X,Y) = f(X-1,Y-1) + f(X,Y-1); } else { f(X,Y) = 0; } }, sub { f(1,1) = 1; f(1,2) = 1; f(2,2) = 1; }; #'# my $height = 5; for my $y (1..$height) { print " " x ($height - $y); for my $x (1..$y) { print $pascal{$x,$y}; } print "\n"; }
Update: fixed, added comma after "Tie::Math" line 6 and right curly on line 12.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Equilateral Pascal's Triangle in perltex
by Coach (Initiate) on Jun 02, 2009 at 04:33 UTC | |
by zentara (Cardinal) on Jun 02, 2009 at 11:06 UTC | |
by Coach (Initiate) on Jun 02, 2009 at 13:17 UTC | |
by Khen1950fx (Canon) on Jun 03, 2009 at 21:52 UTC |