[racket] what's wrong with my code?
I'm really stuck trying to figure this out. Any pointers are useful!
Here's the problem:
f(n) = n if n<4
and
f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) + 4f(n - 4) if n>= 4
Here's my solution so far -- any one know what I'm doing wrong?
(define (f n)
(define (f-iter result i)
(if (> i 4)
result
(f-iter (+ result (* i (- n i))) (+ i 1))
)
)
(if (< n 4)
n
(f-iter 0 1)
)
)
(f 4) ;; should produce 10, produces 10
(f 5) ;; should produce 26, produces 20
(f 6) ;; should produce 63, produces 30
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130120/9e334f32/attachment.html>