From Wikipedia, the free encyclopedia:

 A happy number is defined by the following process:
 Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals   1   (where it will stay),   or it loops endlessly in a cycle which does not include   1.   


 Those numbers for which this process end in   1   are       happy   numbers,   
 while   those numbers   that   do   not   end in   1   are   unhappy   numbers. 


Task

Find and print the first   8   happy numbers.

Display an example of your output here on this page.



See also

   The OEIS entry:   The     happy numbers:   A007770
   The OEIS entry:   The unhappy numbers;   A031177


INT base10 = 10, num happy = 8;
 
PROC next = (INT in n)INT: (
  INT n := in n;
  INT out := 0;
  WHILE n NE 0 DO
    out +:= ( n MOD base10 ) ** 2;
    n := n OVER base10
  OD;
  out
);
 
PROC is happy = (INT in n)BOOL: (
  INT n := in n;
  FOR i WHILE n NE 1 AND n NE 4 DO n := next(n) OD;
  n=1
);
 
INT count := 0;
FOR i WHILE count NE num happy DO
  IF is happy(i) THEN
    count +:= 1;
    print((i, new line))
  FI
OD