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

SICP exercise 1.11

Name: Anonymous 2009-03-05 10:24

Exercise 1.11. 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.


(define (f n)
    (cond ((< n 3) n)
    (else ((+ (f (- n 1))
            (*
                (f (- n 2)) 2)
            (*
                (f (- n 3)) 3))))))


It gives me "The object 4 is not applicable".
Can you guys help me?

Name: Anonymous 2009-03-05 13:59

(define (f n)
    (cond
        ((< n 3)
            n
        )
        (else
            (+
                (   f (- n 1))
                (* (f (- n 2))
                    2
                )
                (* (f (- n 3))
                    3
                )
            )
        )
    )
)

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