Javascript code needed of explination (recursion example)
<p>My main problem is that I cant seem to understand how to solve the problem on paper let alone understand the code, or write my own. Heres the excerpt from Eloquent JavaScript, a book I am reading. </p>

<p>Consider this puzzle: By starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite amount of new numbers can be produced. How would you write a function that, given a number, tries to find a sequence of additions and multiplications that produce that number?</p>

<p>¶ For example, the number 13 could be reached by first multiplying 1 by 3, and then adding 5 twice. The number 15 can not be reached at all.</p>

<p>¶ Here is the solution:</p>

<pre><code> function findSequence(goal) {
   function find(start, history) {
     if (start == goal)
      return history;
     else if (start &gt; goal)
       return null;
     else
       return find(start + 5, "(" + history + " + 5)") ||
              find(start * 3, "(" + history + " * 3)");
   }
   return find(1, "1");
 }

 print(findSequence(24));
</code></pre>
