Author |
Message |
Carey
|
Posted: Mon Apr 07, 2008 7:41 am Post subject: Pascal's Triangle and TriangularArray |
|
|
This is a program to generate any term in Pascal's triangle. It also serves as a demonstration of the difference between recursion and memory recursion. (memory keeps track of the values it has generated). I have also included a class called TriangleArray. This is a class specifically designed to handle pyramid-shaped arrays like the numbers in Pascal's triangle and is generic enough to be used in any program that needs it.
To generate a value in Pascal's triangle simply call
Turing: |
%show the value of row 10, col 5 of Pascal's triangle
put pascal (10, 5)
|
To show Pascal's triangle call
Turing: |
%show Pascal's triangle
putTriangle
|
The method putTriangle is there to show Pascal's triangle up to whatever the constant ROWS is. Be carefull to not make rows too big (>33) of you will get an integer overflow error. (you can correct this by changing the 'Data' type at the top of the program to real instead of int). The constant MEMORY dictate wether you want to use memory recursion or not. Try it both ways and notice the speed delay. The constant MID is the middle text col of the screen (don't change). The constant SPACING is the number of text cols each number occupies. Make it an even number for a better looking triangle. The constant ROWS is how may rows of Pascal's triangle you want to generate with putTriangle. The constants MID, SPACING and ROWS are not needed if you are not using the putTriangle method.
Just post if have suggestions or comments of either the TriangleArray class, Pascal stuff, or memory recursion.
Description: |
|
Download |
Filename: |
Pascal's Triangle - Triangle Array.t |
Filesize: |
3.39 KB |
Downloaded: |
851 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
petree08
|
Posted: Mon Apr 07, 2008 9:57 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
Pretty cool, my compsci class is starting recursion pretty soon, good to see an example like this
|
|
|
|
|
|
Tallguy
|
Posted: Mon Apr 14, 2008 8:33 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
yoo, very well done, the larger numbers are a bit hard to see though, their too close together
|
|
|
|
|
|
repsoccer16
|
Posted: Tue Apr 15, 2008 7:53 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
ya try to spread the numbers out more for the larger ones.
|
|
|
|
|
|
Carey
|
Posted: Wed Apr 16, 2008 10:14 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
Read the instructions. the spacing controls how far apart each number is. up the spacing to spread out the numbers more
|
|
|
|
|
|
repsoccer16
|
Posted: Thu Apr 17, 2008 7:36 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
sorry bud...could have just said it nicely instead of being rude about it.
|
|
|
|
|
|
Carey
|
Posted: Thu Apr 17, 2008 9:56 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
I wasn't trying to be rude. typing doesn't carry emotion very well. Sorry.
|
|
|
|
|
|
repsoccer16
|
Posted: Mon Apr 21, 2008 7:28 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
that's okay
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
nastynika
|
Posted: Mon May 12, 2008 8:29 am Post subject: Re: Pascal's Triangle and TriangularArray |
|
|
how would u amke it so the user can input a colum and row and it would show it?
|
|
|
|
|
|
Carey
|
Posted: Mon May 12, 2008 9:52 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
See the first post
Turing: |
%show the value of row 10, col 5 of Pascal's triangle
put pascal (10, 5)
|
|
|
|
|
|
|
nastynika
|
Posted: Tue May 13, 2008 8:05 am Post subject: Re: Pascal's Triangle and TriangularArray |
|
|
no i mean like a get statement or something where u input a ropw and colum while the program is running
|
|
|
|
|
|
Carey
|
Posted: Wed May 14, 2008 10:36 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
just use variables top store the rows and cols that you want to output then use them to call the pascal method
Turing: |
var row. col :int
get row
get col
put pascal (row, col)
|
|
|
|
|
|
|
BrookeTookie
|
Posted: Wed Apr 30, 2014 9:38 am Post subject: Re: Pascal's Triangle and TriangularArray |
|
|
Is this program Recursive or non recursive?
|
|
|
|
|
|
Insectoid
|
Posted: Wed Apr 30, 2014 10:14 am Post subject: RE:Pascal\'s Triangle and TriangularArray |
|
|
Quote: It also serves as a demonstration of the difference between recursion and memory recursion.
|
|
|
|
|
|
BrookeTookie
|
Posted: Thu May 01, 2014 10:09 am Post subject: Re: Pascal's Triangle and TriangularArray |
|
|
Lol okay, i made a mistake. I was trying to offend anyone or upset anyone by that. I just misread that.
|
|
|
|
|
|
|