[racket] what's wrong with my code?
For one thing, the question you are asking in the code,
(> i 4) ;; i.e., i > 4
is not the same question you ask in your equations,
n < 4
so, for starters, it would seem you need the two questions to be in agreement.
Best,
jmj
--
Sent from my Android phone with K-9 Mail.
Robert Hume <rhume55 at gmail.com> wrote:
>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
>
>
>------------------------------------------------------------------------
>
>____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130120/200e1a50/attachment.html>