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


#ToFind=8
#MaxTests=100
#True = 1: #False = 0
Declare is_happy(n)
 
If OpenConsole()
  Define i=1,Happy
  Repeat
    If is_happy(i)
      Happy+1
      PrintN("#"+Str(Happy)+RSet(Str(i),3))
    EndIf
    i+1
  Until Happy>=#ToFind
  ;
  Print(#CRLF$+#CRLF$+"Press ENTER to exit"): Input()
  CloseConsole()
EndIf
 
Procedure is_happy(n)
  Protected i,j=n,dig,sum
  Repeat
    sum=0
    While j
      dig=j%10
      j/10
      sum+dig*dig
    Wend
    If sum=1: ProcedureReturn #True: EndIf  
    j=sum
    i+1
  Until i>#MaxTests
  ProcedureReturn #False
EndProcedure