Sha256: 00b4773b38ef7dc24a9eac74b3c00d5b8283853667668bd7446b9e3cb809844f
Contents?: true
Size: 469 Bytes
Versions: 3
Compression:
Stored size: 469 Bytes
Contents
defmodule PrimeFactors do @spec factors_for(pos_integer) :: [pos_integer] def factors_for(number) do do_factors(number) end defp do_factors(_, i \\ 2, acc \\ []) defp do_factors(1, _, acc), do: Enum.reverse(acc) defp do_factors(n, i, acc) when n < i * i, do: Enum.reverse(acc, [n]) defp do_factors(n, i, acc) when rem(n, i) == 0, do: do_factors(div(n, i), i, [i | acc]) defp do_factors(n, i, acc), do: do_factors(n, i + 1, acc) end
Version data entries
3 entries across 3 versions & 1 rubygems