Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Pascal triange...

by Abigail-II (Bishop)
on Jun 19, 2002 at 13:59 UTC ( [id://175683]=note: print w/replies, xml ) Need Help??


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

It's not hard to see how it works. First thing to realize that one way of calculating the next line in the triangle is to take the previous line twice, shift one of the line one position to the right, and then add the elements piecewise. For instance:
    1  3  3  1
       1  3  3  1
    ------------- +
    1  4  6  4  1
But if you look carefully, you see that to each element, we add the element to the left of it, except for the two elements on the far ends - which will both be one (a "new" 1 on the right, and the one of the left remains "as is").

And that's how the program works. We first add a new element (with the push), then for each element, we add the preceding one. We have to work backwards of course, which is achieved by the reverse.

Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-28 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found