Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Pascal triange...

by kiat (Vicar)
on Jun 19, 2002 at 13:40 UTC ( #175672=note: print w/replies, xml ) Need Help??


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

Hello! Abigail-II,

I like your smaller function (it's really elegant) but I don't understand how it works, even though it's only a few lines. Could you explain the parts to me?

Thanks in anticipation :)

kiat

Replies are listed 'Best First'.
Re: Pascal triange...
by Abigail-II (Bishop) on Jun 19, 2002 at 13:59 UTC
    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
Node Status?
node history
Node Type: note [id://175672]
help
Chatterbox?
[Corion]: DST does that to everybody...
Corion attempts to find who to address to better target his drive-by patches
[Corion]: This time it's for the Duktape embedded Javascript engine, which would be nice to have IMO, but doesn't compile on Windows currently
[Corion]: I imagine it would be fun to have WWW::Mechanize:: Duktape, but I haven't seen a web browser written in Javascript yet, except the ones distributed with PhantomJs

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-03-27 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (319 votes). Check out past polls.