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