Pascal's triangle
Post: #1
 roadrunner Senior Member Posts: 438 Joined: Jun 2015
Pascal's triangle
Function pascal(x) returns a level of Pascal's triangle.

Example:

pascal(7) returns {1,7,21,35,35,21,7,1}
the 7th level of Pascal's triangle

Code:
#pragma mode(separator(.,;) integer(h32)) EXPORT pascal(x) BEGIN  case   if x < 1 then {1};end;   if x < 2 then {1,1}; end;  default   concat(1,execon("&1+&2",pascal(x−1)),1);  end; END;
09-01-2015, 04:30 PM
Post: #2
 Gerald H Senior Member Posts: 1,623 Joined: May 2014
RE: Pascal's triangle
Isn't {1,7,21,35,35,21,7,1} the 8th line?
09-02-2015, 01:15 AM
Post: #3
 roadrunner Senior Member Posts: 438 Joined: Jun 2015
RE: Pascal's triangle
(09-01-2015 04:30 PM)Gerald H Wrote:  Isn't {1,7,21,35,35,21,7,1} the 8th line?

Here: http://ptri1.tripod.com/ they start counting with row zero, making {1,7,21,35,35,21,7,1} row 7. But Blaise Pascal himself, it seems, would have agreed with you: https://en.wikipedia.org/wiki/Pascal%27s...Pascal.jpg

09-02-2015, 02:58 PM
Post: #4
 Joe Horn Senior Member Posts: 1,985 Joined: Dec 2013
RE: Pascal's triangle
Alternative method, using a single expression:
pcoeff(makemat(-1,j,1)) --> jth row of Pascal's Triangle
Works both in Home and CAS.

<0|ɸ|0>
-Joe-
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)