|
common scheme & pascal's triangle help
|
View this Thread in Original format
| whiskers |
Exercise 1.12. The following pattern of numbers is called Pascal's triangle.
code:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 4 10 10 1
The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it. Write a procedure that computes elements of Pascal's triangle by means of a recursive process.
before i waste hours on this exercise, which is only 1/6 of my homework, is it even possible to do so with Scheme? the thing is, they didn't teach us the language at ALL. i don't even know if there are any lists or strings or anything like that, and i'm prone to believe it's impossible to do this without strings...
can someone confirm or deny my thoughts on this POS? |
|
|
| DJ Nuclear |
| quote: | Originally posted by whiskers
Exercise 1.12. The following pattern of numbers is called Pascal's triangle.
code:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 4 10 10 1
The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it. Write a procedure that computes elements of Pascal's triangle by means of a recursive process.
before i waste hours on this exercise, which is only 1/6 of my homework, is it even possible to do so with Scheme? the thing is, they didn't teach us the language at ALL. i don't even know if there are any lists or strings or anything like that, and i'm prone to believe it's impossible to do this without strings...
can someone confirm or deny my thoughts on this POS? |
You should be able to program this recursively, I'm pretty sure. And, you wouldn't need strings to do this, just integers, multiplication, and a print to console/screen function.
edit: this language seems to be extended lisp, so you _should_ be able to do it. I dunno how though, I don't really code lisp/scheme.
ftp://ftp.cs.utexas.edu/pub/garbage/cs345/schintro-v14/schintro_toc.html |
|
|
| SuperFarStucker |
| Either I'm stupid or your triangle's 1 4 10 10 1 base is on some serious crack rock, shouldn't it be 1 5 10 10 5 1? |
|
|
| maxstradamus |
| quote: | Originally posted by SuperFarStucker
Either I'm stupid or your triangle's 1 4 10 10 1 base is on some serious crack rock, shouldn't it be 1 5 10 10 5 1? |
that's exactly what i was thinking
or 1, 5, 10, 5, 1 unless the bottom row has 6 digits |
|
|
| Boomer187 |
| quote: | Originally posted by maxstradamus
that's exactly what i was thinking
or 1, 5, 10, 5, 1 unless the bottom row has 6 digits |
its a triangle so it does..
last row would be 1, 5, 10, 10, 5, 1
just follow the instructions. each number is the sum of the 2 digits above it.
I like pascals wager better. Go to church cause you have nothing to lose. wait I think that was it.. |
|
|
| maxstradamus |
edit: i meant 6 numbers not digits.
and yes in this case it would have to be 1, 5, 10, 10, 5, 1 |
|
|
| mezzir |
what class is this for anyways?
like do you need a recursive forumla algebra 2 style or C++ code |
|
|
| whiskers |
yeh, i messed up on the last row. computer language paradigms is not a fun class at all, especially if your teacher is a psycho who assigns you every single problem in the book.
i was just having trouble visualizing how i'm supposed to know what to add because i could program this in c++ and even in pascal (which is a hard language to program in), but only using tables / matrices. i've never used a bare language before and i can't understand how i should keep track of the previous row... or am i supposed to recalculate it over and over? how am i to know what to add anyway...
i'm probably not even gonna bother doing this stuff... each hw is like 6 problems and worth 10 points... bleh. |
|
|
| yellowalfa |
| I just wanted to say it's weird, we're doing the same exact thing only in the class "principles of mathmatics" I could continue the triangle for you, but I don't know how to apply it in programing, sorry! :conf: |
|
|
| DJ Nuclear |
| quote: | Originally posted by whiskers
yeh, i messed up on the last row. computer language paradigms is not a fun class at all, especially if your teacher is a psycho who assigns you every single problem in the book.
i was just having trouble visualizing how i'm supposed to know what to add because i could program this in c++ and even in pascal (which is a hard language to program in), but only using tables / matrices. i've never used a bare language before and i can't understand how i should keep track of the previous row... or am i supposed to recalculate it over and over? how am i to know what to add anyway...
i'm probably not even gonna bother doing this stuff... each hw is like 6 problems and worth 10 points... bleh. |
http://archive.ncsa.uiuc.edu/Classe...bholt/comb.html
http://ptri1.tripod.com/
http://ecademy.agnesscott.edu/~lrid.../Pascalmath.htm
http://mail.python.org/pipermail/ed...ary/000066.html <-- Implementation of the algorithm in python, recursively and non-recursively.
Those may help. |
|
|
| mezzir |
hm
no help in C(++) or pascal
i know visual basic, true basic, and java
:( |
|
|
| whiskers |
thanks, i know how the triangle works and the binomial stuff, but the book's being retarded about it.
i'm giving up on it. |
|
|
|
|