Skip to content

Instantly share code, notes, and snippets.

@hpyhacking
Created April 4, 2013 03:59
Show Gist options
  • Save hpyhacking/5307715 to your computer and use it in GitHub Desktop.
Save hpyhacking/5307715 to your computer and use it in GitHub Desktop.
-module(sample).
-export([combos/1, combos/2]).
combos(1, L) -> [[X] || X <-L];
combos(K, L) when K == length(L) -> [L];
combos(K, [H|T]) ->
[[H | Subcombos] || Subcombos <- combos(K-1, T)]
++(combos(K, T)).
combos(L) ->
lists:foldl(
fun(K, Acc) -> Acc++(combos(K, L)) end,
[[]],
lists:seq(1, length(L))
).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment