Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,578 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,951 people online right now. Registration is fast and FREE... Join Now!




Iteration Help

 
Reply to this topicStart new topic

Iteration Help, Solving f(x) = x if x<3 f(x) = f(x-1)+ 2f(x-2) + 3f(x-3) in an ite

R3DLIN3
1 Oct, 2008 - 04:31 PM
Post #1

New D.I.C Head
*

Joined: 8 Aug, 2007
Posts: 2


My Contributions
Hello I had a lab assignment that wanted me to solve the function f(x) = x if x<3 f(x) = f(x-1)+ 2f(x-2) + 3f(x-3) in an iteration loop using the scheme programming language. I couldn't figure it out, was just wondering if someone could show me a solution it doesn't have to be in scheme i also know c++ java and c#. I have already got a grade on the code I wrote that doesn't work correctly so this isn't cheating I simply want to know the answer. Here is my code

CODE
(define (fit n total1 total2 total3 progress)
(if (< progress n)
  (if (< n 3)
      n
       (fit n
        (fit (- n 1) total1 total2 total3 0)
        (fit (- n 2) total1 total2 total3 0)
        (fit (- n 3) total1 total2 total3 0)
        (+ progress 1))
     )
  (+ total1 (* 2 total2) (* 3 total3))
)
)

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:23AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month