Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Happy-numbers/M2000-Interpreter/happy-numbers.m2000
Normal file
32
Task/Happy-numbers/M2000-Interpreter/happy-numbers.m2000
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue