Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Anti-primes/Erlang/anti-primes.erl
Normal file
28
Task/Anti-primes/Erlang/anti-primes.erl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
divcount(N) -> divcount(N, 1, 0).
|
||||
|
||||
divcount(N, D, Count) when D*D > N -> Count;
|
||||
divcount(N, D, Count) ->
|
||||
Divs = case N rem D of
|
||||
0 ->
|
||||
case N - D*D of
|
||||
0 -> 1;
|
||||
_ -> 2
|
||||
end;
|
||||
_ -> 0
|
||||
end,
|
||||
divcount(N, D + 1, Count + Divs).
|
||||
|
||||
|
||||
antiprimes(N) -> antiprimes(N, 1, 0, []).
|
||||
|
||||
antiprimes(0, _, _, L) -> lists:reverse(L);
|
||||
antiprimes(N, M, Max, L) ->
|
||||
Count = divcount(M),
|
||||
case Count > Max of
|
||||
true -> antiprimes(N-1, M+1, Count, [M|L]);
|
||||
false -> antiprimes(N, M+1, Max, L)
|
||||
end.
|
||||
|
||||
|
||||
main(_) ->
|
||||
io:format("The first 20 anti-primes are ~w~n", [antiprimes(20)]).
|
||||
Loading…
Add table
Add a link
Reference in a new issue