Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Almost-prime/Elixir/almost-prime.elixir
Normal file
23
Task/Almost-prime/Elixir/almost-prime.elixir
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
defmodule Factors do
|
||||
def factors(n), do: factors(n,2,[])
|
||||
|
||||
defp factors(1,_,acc), do: acc
|
||||
defp factors(n,k,acc) when rem(n,k)==0, do: factors(div(n,k),k,[k|acc])
|
||||
defp factors(n,k,acc) , do: factors(n,k+1,acc)
|
||||
|
||||
def kfactors(n,k), do: kfactors(n,k,1,1,[])
|
||||
|
||||
defp kfactors(_tn,tk,_n,k,_acc) when k == tk+1, do: IO.puts "done! "
|
||||
defp kfactors(tn,tk,_n,k,acc) when length(acc) == tn do
|
||||
IO.puts "K: #{k} #{inspect acc}"
|
||||
kfactors(tn,tk,2,k+1,[])
|
||||
end
|
||||
defp kfactors(tn,tk,n,k,acc) do
|
||||
case length(factors(n)) do
|
||||
^k -> kfactors(tn,tk,n+1,k,acc++[n])
|
||||
_ -> kfactors(tn,tk,n+1,k,acc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Factors.kfactors(10,5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue