Sha256: 043f792e8e9b7b23259fd845873bcbdf212f0e9a4136adc6966066930d0b3f8b

Contents?: true

Size: 420 Bytes

Versions: 69

Compression:

Stored size: 420 Bytes

Contents

defmodule PrimeFactors do
  @spec factors_for(pos_integer) :: [pos_integer]
  def factors_for(number) do
    do_factors(number, 2, [])
  end

  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

69 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.179 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.178 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.177 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.176 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.175 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.174 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.173 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.172 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.171 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.170 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.169 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.167 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.166 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.165 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.164 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.163 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.162 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.161 tracks/elixir/exercises/prime-factors/example.exs
trackler-2.2.1.160 tracks/elixir/exercises/prime-factors/example.exs