Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Happy-numbers/Miranda/happy-numbers.miranda
Normal file
22
Task/Happy-numbers/Miranda/happy-numbers.miranda
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue