22 lines
596 B
Text
22 lines
596 B
Text
main :: [sys_message]
|
|
main = [Stdout (lay (map show (take 8 happynumbers)))]
|
|
|
|
happynumbers :: [num]
|
|
happynumbers = filter ishappy [1..]
|
|
|
|
ishappy :: num->bool
|
|
ishappy n = 1 $in loop (iterate sumdigitsquares n)
|
|
|
|
sumdigitsquares :: num->num
|
|
sumdigitsquares 0 = 0
|
|
sumdigitsquares n = (n mod 10)^2 + sumdigitsquares (n div 10)
|
|
|
|
loop :: [*]->[*]
|
|
loop = loop' []
|
|
where loop' mem (a:as) = mem, if a $in mem
|
|
= loop' (a:mem) as, otherwise
|
|
|
|
in :: *->[*]->bool
|
|
in val [] = False
|
|
in val (a:as) = True, if a=val
|
|
= val $in as, otherwise
|