Population count: Difference between revisions

Add CLU
(→‎{{header|Ring}}: wrong output, 3 is not the first Evil number, 4 & 16 were in the wrong bin, removed stdlib.ring requirement.)
(Add CLU)
Line 1,318:
; ==> (1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59)
</pre>
 
=={{header|CLU}}==
<lang clu>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</lang>
{{out}}
<pre> 1 2 2 4 3 6 6 5 6 8 9 13 10 11 14 15 11 14 14 17 17 20 19 22 16 18 24 30 25 25
0 3 5 6 9 10 12 15 17 18 20 23 24 27 29 30 33 34 36 39 40 43 45 46 48 51 53 54 57 58
1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59</pre>
 
=={{header|COBOL}}==
2,094

edits