Happy numbers: Difference between revisions
m
→{{header|Julia}}: update for Julia versions > 0.7
(Added Easylang) |
m (→{{header|Julia}}: update for Julia versions > 0.7) |
||
Line 3,972:
<syntaxhighlight lang="julia">
function happy(x)
happy_ints =
int_try = 1
while length(happy_ints) < x
n = int_try
past =
while n != 1
push!(past, n)
n == 1 && push!(happy_ints,int_try)
int_try += 1
Line 4,000 ⟶ 4,001:
<syntaxhighlight lang="julia">sumhappy(n) = sum(x->x^2, digits(n))
function ishappy(x, mem = Int[])
x == 1 ? true :
x in mem ? false :
ishappy(sumhappy(x), [mem ; x])
end
nexthappy
▲happy(n) = [z = 1 ; [z = nexthappy(z) for i = 1:n-1]]
</syntaxhighlight>
{{Out}}
Line 4,018:
{{trans|C}}
<syntaxhighlight lang="julia">const CACHE = 256
buf = zeros(Int, CACHE)
buf[
function happy(n)
if n < CACHE
Line 4,026:
buf[n] = 2
end
nn = n
while nn != 0
nn, x = divrem(nn
end
x = happy(
n < CACHE && (buf[n] = 2 - x)
return x
end
function main()
i, counter = 1
while counter > 0
if happy(i)
counter -= 1
end
i += 1
end
return i - 1
end
=={{header|K}}==
|