title: List and List value manipulations in Erlang
body: <p>I am  learning some Erlang and doing exercises from the book, so i got stuck on one of them. It`s better if i quote the whole problem and then explain what i have done so far: 
  "A positive number is happy if by repeated application
  of the procedure below the number 1 is reached.
  1. Square each of the digits of the number
  2. Compute the sum of all the squares
  For example, if you start with 19:</p>
  
  <pre><code> 1 * 1 + 9 * 9 = 1 + 81 = 82
   8 * 8 + 2 * 2 = 64 + 4 = 68
   6 * 6 + 8 * 8 = 36 + 64 = 100
   1 * 1 + 0 * 0 + 0 * 0 = 1 + 0 + 0 = 1 
  </code></pre>
  
  <p>(i.e. 19 is a happy number)
  How do you know when a number is not happy? In fact, every unhappy
  number will eventually reach the cycle 4, 16, 37, 58, 89, 145, 42, 20, 4,
  … thus it is sufficient to look for any number in that cycle (say 4), and
  conclude that the original number is unhappy.
  Write the functions happy/1, and all_happy/2, which returns
  whether a number is happy or not (true or false) and all happy numbers
  between N and M respectively. (Hint: use the functions digitize and
  sum).
  Examples:</p>
  
  <pre><code> happy(28) → true
   happy(15) → false
   happy(5, 25) → [7, 10, 13, 19, 23]"
  </code></pre>
  
  <p>So, I have created a digitizer/1, which given a positive number N returns a list of the digits in that number: </p>
  
  <pre><code>digitize(N) -&gt; digitize1(N, []).
  digitize1(N, Acc) when N &gt; 0 -&gt; digitize1(N div 10, [N rem 10| Acc]);
  digitize1(N, Acc) when N == 0 -&gt; Acc.
  </code></pre>
  
  <p>, and sum/1:</p>
  
  <pre><code>sum(N) when  N &gt; 0 -&gt; N + sum(N-1);
  sum(0) -&gt;   0.
  </code></pre>
  
  <p>So for the happy numbers what i have done so far is this:</p>
  
  <pre><code>happy(N) -&gt; happy1(digitize(N), []).
  happy1([], Acc) -&gt; (Acc);
  happy1([Head|Tail], Acc1) -&gt; happy1(Tail, [Head * Head|Acc1]).
  </code></pre>
  
  <p>It squares the elements of the list, but i cannot come up with idea of how to sum them and do it again recursively until it reaches 1 or 4. Any help or ideas?
  And for the second part(all_happy/2), in my non-competent opinion i should use list comprehension, but again, I`m not quite sure how to implement it. Thanks for your time.</p>