19 lines
289 B
Text
19 lines
289 B
Text
isHappy = {|n|
|
|
sqf = {|x| x^2}
|
|
seen = new set[n]
|
|
|
|
while true
|
|
{
|
|
n = sum[map[sqf, integerDigits[n]]]
|
|
if n == 1
|
|
return true
|
|
|
|
if seen.contains[n]
|
|
return false
|
|
else
|
|
seen.put[n]
|
|
}
|
|
}
|
|
|
|
|
|
println[first[select[count[1], isHappy], 8]]
|