Jump to content

Population count: Difference between revisions

m (→‎{{header|Phix}}: syntax coloured)
Line 3,143:
first 30 odious numbers: 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|Picat}}==
<lang Picat>go =>
println(powers_of_three=[pop_count(3**I) : I in 0..29]),
println('evil_numbers '=take_n($evil_number, 30,0)),
println('odious_numbers '=take_n($odious_number, 30,0)),
nl.
 
% Get the first N numbers that satisfies function F, starting with S
take_n(F,N,S) = L =>
I = S,
C = 0,
L = [],
while(C < N)
if call(F,I) then
L := L ++ [I],
C := C + 1
end,
I := I + 1
end.
 
evil_number(N) => pop_count(N) mod 2 == 0.
odious_number(N) => pop_count(N) mod 2 == 1.
 
pop_count(N) = sum([1: I in N.to_binary_string(), I = '1']).</lang>
 
{{out}}
<pre>powers_of_three = [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]
evil_numbers = [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]
odious_numbers = [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|PicoLisp}}==
495

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.