2016-12-05 23:44:36 +01:00
|
|
|
func happy(n) is cached {
|
|
|
|
|
static seen = Hash()
|
|
|
|
|
|
|
|
|
|
return true if n.is_one
|
2018-08-17 15:15:24 +01:00
|
|
|
return false if seen.exists(n)
|
2016-12-05 23:44:36 +01:00
|
|
|
|
|
|
|
|
seen{n} = 1
|
2018-08-17 15:15:24 +01:00
|
|
|
happy(n.digits.sum { _*_ })
|
2016-12-05 23:44:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-17 23:21:07 -08:00
|
|
|
say happy.first(8)
|