32 lines
928 B
Text
32 lines
928 B
Text
Function FactoryHappy {
|
|
sumOfSquares= lambda (n) ->{
|
|
k$=str$(abs(n),"")
|
|
Sum=0
|
|
For i=1 to len(k$)
|
|
sum+=val(mid$(k$,i,1))**2
|
|
Next i
|
|
=sum
|
|
}
|
|
IsHappy=Lambda sumOfSquares (n) ->{
|
|
Inventory sequence
|
|
While n<>1 {
|
|
Append sequence, n
|
|
n=sumOfSquares(n)
|
|
if exist(sequence, n) then =false : Break
|
|
}
|
|
=True
|
|
}
|
|
=Lambda IsHappy ->{
|
|
numleft=8
|
|
numToTest=1
|
|
While numleft {
|
|
if ishappy(numToTest) Then {
|
|
Print numToTest
|
|
numleft--
|
|
}
|
|
numToTest++
|
|
}
|
|
}
|
|
}
|
|
PrintHappy=factoryHappy()
|
|
Call PrintHappy()
|