Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/Population-count/Erlang/population-count-1.erl
Normal file
50
Task/Population-count/Erlang/population-count-1.erl
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
-module(population_count).
|
||||
-export([popcount/1]).
|
||||
|
||||
-export([task/0]).
|
||||
|
||||
popcount(N) ->
|
||||
popcount(N,0).
|
||||
|
||||
popcount(0,Acc) ->
|
||||
Acc;
|
||||
popcount(N,Acc) ->
|
||||
popcount(N div 2, Acc + N rem 2).
|
||||
|
||||
threes(_,0,Acc) ->
|
||||
lists:reverse(Acc);
|
||||
threes(Threes,N,Acc) ->
|
||||
threes(Threes * 3, N-1, [popcount(Threes)|Acc]).
|
||||
|
||||
threes(N) ->
|
||||
threes(1,N,[]).
|
||||
|
||||
evil(_,0,Acc) ->
|
||||
lists:reverse(Acc);
|
||||
evil(N,Count,Acc) ->
|
||||
case popcount(N) rem 2 of
|
||||
0 ->
|
||||
evil(N+1,Count-1,[N|Acc]);
|
||||
1 ->
|
||||
evil(N+1,Count,Acc)
|
||||
end.
|
||||
evil(Count) ->
|
||||
evil(0,Count,[]).
|
||||
|
||||
odious(_,0,Acc) ->
|
||||
lists:reverse(Acc);
|
||||
odious(N,Count,Acc) ->
|
||||
case popcount(N) rem 2 of
|
||||
1 ->
|
||||
odious(N+1,Count-1,[N|Acc]);
|
||||
0 ->
|
||||
odious(N+1,Count,Acc)
|
||||
end.
|
||||
odious(Count) ->
|
||||
odious(1,Count,[]).
|
||||
|
||||
|
||||
task() ->
|
||||
io:format("Powers of 3: ~p~n",[threes(30)]),
|
||||
io:format("Evil:~p~n",[evil(30)]),
|
||||
io:format("Odious:~p~n",[odious(30)]).
|
||||
8
Task/Population-count/Erlang/population-count-2.erl
Normal file
8
Task/Population-count/Erlang/population-count-2.erl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
61> population_count:task().
|
||||
Powers of 3: [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:[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:[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]
|
||||
ok
|
||||
Loading…
Add table
Add a link
Reference in a new issue