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


ISHAPPY(N)
 ;Determines if a number N is a happy number
 ;Note that the returned strings do not have a leading digit unless it is a happy number
 IF (N'=N\1)!(N<0) QUIT "Not a positive integer"
 NEW SUM,I
 ;SUM is the sum of the square of each digit
 ;I is a loop variable
 ;SEQ is the sequence of previously checked SUMs from the original N
 ;If it isn't set already, initialize it to an empty string
 IF $DATA(SEQ)=0 NEW SEQ SET SEQ=""
 SET SUM=0
 FOR I=1:1:$LENGTH(N) DO
 .SET SUM=SUM+($EXTRACT(N,I)*$EXTRACT(N,I))
 QUIT:(SUM=1) SUM
 QUIT:$FIND(SEQ,SUM)>1 "Part of a sequence not containing 1"
 SET SEQ=SEQ_","_SUM
 QUIT $$ISHAPPY(SUM)
HAPPY(C) ;Finds the first C happy numbers
 NEW I
 ;I is a counter for what integer we're looking at
 WRITE !,"The first "_C_" happy numbers are:"
 FOR I=1:1 QUIT:C<1  SET Q=+$$ISHAPPY(I) WRITE:Q !,I SET:Q C=C-1
 KILL I
 QUIT