title: No idea how to solve SICP exercise 1.11
body: <p><a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_thm_1.11" rel="noreferrer">Exercise 1.11</a>:</p>
  
  <blockquote>
    <p>A function <code>f</code> is defined by the rule that <code>f(n) = n</code> if <code>n &lt; 3</code> and <code>f(n) = f(n - 1) + 2f(n  - 2) + 3f(n - 3)</code> if <code>n &gt; 3</code>. Write a procedure that computes <code>f</code> by means of a recursive process. Write a procedure that computes <code>f</code> by means of an iterative process. </p>
  </blockquote>
  
  <p>Implementing it recursively is simple enough. But I couldn't figure out how to do it iteratively. I tried comparing with the Fibonacci example given, but I didn't know how to use it as an analogy. So I gave up (shame on me) and Googled for <a href="http://www.billthelizard.com/2009/11/sicp-exercise-111.html" rel="noreferrer">an explanation</a>, and I found this:</p>
  
  <pre><code>(define (f n)
     (if (&lt; n 3)
         n
         (f-iter 2 1 0 n)))
  
  (define (f-iter a b c count)
     (if (&lt; count 3)
         a
         (f-iter (+ a (* 2 b) (* 3 c))
                 a
                 b
                 (- count 1))))
  </code></pre>
  
  <p>After reading it, I understand the code and how it works. But what I don't understand is the process needed to get from the recursive definition of the function to this. I don't get how the code could have formed in someone's head.</p>
  
  <p>Could you explain the thought process needed to arrive at the solution?</p>