Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,31 @@
defmodule AntiPrimes do
def divcount(n) when is_integer(n), do: divcount(n, 1, 0)
def divcount(n, d, count) when d * d > n, do: count
def divcount(n, d, count) do
divs = case rem(n, d) do
0 ->
case n - d * d do
0 -> 1
_ -> 2
end
_ -> 0
end
divcount(n, d + 1, count + divs)
end
def antiprimes(n), do: antiprimes(n, 1, 0, [])
def antiprimes(0, _, _, l), do: Enum.reverse(l)
def antiprimes(n, m, max, l) do
count = divcount(m)
case count > max do
true -> antiprimes(n-1, m+1, count, [m|l])
false -> antiprimes(n, m+1, max, l)
end
end
def main() do
:io.format("The first 20 anti-primes are ~w~n", [antiprimes(20)])
end
end