Sha256: 77f954a8e645aaf3a47c5f0af0c7eb2d18f0cb4713f8861d9ad41ded27c6b7ce

Contents?: true

Size: 373 Bytes

Versions: 69

Compression:

Stored size: 373 Bytes

Contents

defmodule SumOfMultiples do
  @doc """
  Adds up all numbers from 1 to a given end number that are multiples of the factors provided.
  """
  @spec to(non_neg_integer, [non_neg_integer]) :: non_neg_integer
  def to(limit, factors) do
    Enum.reduce(1..(limit - 1), 0, fn n, acc ->
      if Enum.any?(factors, &(rem(n, &1) == 0)), do: acc + n, else: acc
    end)
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

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