Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pascal triange...

by Abigail-II (Bishop)
on Jun 19, 2002 at 17:04 UTC ( #175779=note: print w/ replies, xml ) Need Help??


in reply to Re: Pascal triange...
in thread Pascal's triangle...

Here's a variation on the theme. The difference is that this version doesn't change @row using pushes. It's going to be sized right the first time.

sub pascal { my @row = (0) x $_ [0]; $row [0] = 1; foreach (1 .. shift) { print "@row[0 .. $_ - 1]\n"; $row [$_] += $row [$_ - 1] for reverse 1 .. @row; } }

Abigail


Comment on Re: Pascal triange...
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Pascal triange...
by Burak (Chaplain) on Dec 25, 2003 at 14:35 UTC
    Maybe we can add space padding to your function :)
    sub pascal { my $max = shift or return; my @row = (0) x $max; $row[0] = 1; foreach (1 .. $max) { print " " x ($max - $_),"@row[0 .. $_ - 1]\n"; $row[$_] += $row[$_ - 1] for reverse 1 .. @row; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://175779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2015-07-30 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls