Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Happy-numbers/Icon/happy-numbers.icon
Normal file
17
Task/Happy-numbers/Icon/happy-numbers.icon
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
procedure main(arglist)
|
||||
local n
|
||||
n := arglist[1] | 8 # limiting number of happy numbers to generate, default=8
|
||||
writes("The first ",n," happy numbers are:")
|
||||
every writes(" ", happy(seq()) \ n )
|
||||
write()
|
||||
end
|
||||
|
||||
procedure happy(i) #: returns i if i is happy
|
||||
local n
|
||||
|
||||
if 4 ~= (0 <= i) then { # unhappy if negative, 0, or 4
|
||||
if i = 1 then return i
|
||||
every (n := 0) +:= !i ^ 2
|
||||
if happy(n) then return i
|
||||
}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue