Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Happy-numbers/CLU/happy-numbers.clu
Normal file
36
Task/Happy-numbers/CLU/happy-numbers.clu
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
sum_dig_sq = proc (n: int) returns (int)
|
||||
sum_sq: int := 0
|
||||
while n > 0 do
|
||||
sum_sq := sum_sq + (n // 10) ** 2
|
||||
n := n / 10
|
||||
end
|
||||
return (sum_sq)
|
||||
end sum_dig_sq
|
||||
|
||||
is_happy = proc (n: int) returns (bool)
|
||||
nn: int := sum_dig_sq(n)
|
||||
while nn ~= n cand nn ~= 1 do
|
||||
n := sum_dig_sq(n)
|
||||
nn := sum_dig_sq(sum_dig_sq(nn))
|
||||
end
|
||||
return (nn = 1)
|
||||
end is_happy
|
||||
|
||||
happy_numbers = iter (start, num: int) yields (int)
|
||||
n: int := start
|
||||
while num > 0 do
|
||||
if is_happy(n) then
|
||||
yield (n)
|
||||
num := num-1
|
||||
end
|
||||
n := n+1
|
||||
end
|
||||
end happy_numbers
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
for i: int in happy_numbers(1, 8) do
|
||||
stream$putl(po, int$unparse(i))
|
||||
end
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue