Skip to content

Instantly share code, notes, and snippets.

@Andy-Richards
Created May 20, 2014 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andy-Richards/99d7b4bcecf729047f80 to your computer and use it in GitHub Desktop.
Save Andy-Richards/99d7b4bcecf729047f80 to your computer and use it in GitHub Desktop.
defmodule Combinations do
# See http://rosettacode.org/wiki/Combinations#Erlang
def comb(0, _), do: [[]];
def comb(_, []), do: [];
def comb(n, [h | t]) do
lc = for l <- comb(n - 1, t), do: [h | l]
lc ++ comb(n, t)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment