Packages

A helper library with functions of Mathematics Combinations

Current section

Files

Jump to
math_combinations lib array_combination.ex
Raw

lib/array_combination.ex

defmodule ArrayCombination do
def of([h|t], limit), do: comb(limit, [h|t])
defp comb(0, _), do: [[]]
defp comb(_, []), do: []
defp comb(m, [h|t]) do
(for l <- comb(m-1, t), do: [h|l]) ++ comb(m, t)
end
end