Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SICP

Name: Anonymous 2007-11-24 19:27

Hello /prog/
I am reading SICP, should i do all exercises of the book?
I can't wrap my head around the code.
I've even googled for solutions, but i have to write them down and follow/write each call with pencil.

Seriously, i wouldn't have problem with most of the algorithms given if i could use some other language.

Do i fail at maths?
help.

Name: Anonymous 2007-11-25 20:33

OP here, so .. i am doing this exercise, write an iterative factorial.

Looking at the recursive one, we see

(define (f n) (* n (f (- n 1))))

There's only one call to itself, therefore writing it as an iterative function is easy.

however, then it asks me to write
A function f is defined by the rule that f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n> 3. Write a procedure that computes f by means of a recursive process. Write a procedure that computes f by means of an iterative process.

I simply cannot come up with something, each function results to 3 calls to itself if n>2.

How the fuck?? ... how.

Can someone please explain?
I mean, just the logic, seriously.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List