Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Population-count/Picat/population-count.picat
Normal file
23
Task/Population-count/Picat/population-count.picat
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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']).
|
||||
Loading…
Add table
Add a link
Reference in a new issue