Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Population-count/CLU/population-count.clu
Normal file
46
Task/Population-count/CLU/population-count.clu
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
pop_count = proc (n: int) returns (int)
|
||||
p: int := 0
|
||||
while n>0 do
|
||||
p := p + n//2
|
||||
n := n/2
|
||||
end
|
||||
return(p)
|
||||
end pop_count
|
||||
|
||||
evil = proc (n: int) returns (bool)
|
||||
return(pop_count(n)//2 = 0)
|
||||
end evil
|
||||
|
||||
odious = proc (n: int) returns (bool)
|
||||
return(~evil(n))
|
||||
end odious
|
||||
|
||||
first = iter (n: int, p: proctype (int) returns (bool)) yields (int)
|
||||
i: int := 0
|
||||
while n>0 do
|
||||
if p(i) then
|
||||
yield(i)
|
||||
n := n-1
|
||||
end
|
||||
i := i+1
|
||||
end
|
||||
end first
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
for i: int in int$from_to(0,29) do
|
||||
stream$putright(po, int$unparse(pop_count(3**i)), 3)
|
||||
end
|
||||
stream$putl(po, "")
|
||||
|
||||
for i: int in first(30, evil) do
|
||||
stream$putright(po, int$unparse(i), 3)
|
||||
end
|
||||
stream$putl(po, "")
|
||||
|
||||
for i: int in first(30, odious) do
|
||||
stream$putright(po, int$unparse(i), 3)
|
||||
end
|
||||
stream$putl(po, "")
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue