27 lines
437 B
Text
27 lines
437 B
Text
func happy(n) {
|
|
var m = []
|
|
while n > 1 {
|
|
m.Add(n)
|
|
var x = n
|
|
n = 0
|
|
while x > 0 {
|
|
var d = x % 10
|
|
n += d * d
|
|
x /= 10
|
|
}
|
|
if m.IndexOf(n) != -1 {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
var (n, found) = (1, 0)
|
|
while found < 8 {
|
|
if happy(n) {
|
|
print("\(n) ", terminator: "")
|
|
found += 1
|
|
}
|
|
n += 1
|
|
}
|
|
print()
|