Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created December 13, 2013 23:23
Show Gist options
  • Select an option

  • Save thomasballinger/7953334 to your computer and use it in GitHub Desktop.

Select an option

Save thomasballinger/7953334 to your computer and use it in GitHub Desktop.
def combs(array, n)
if array.length < n
[]
elsif n == 0
[[]]
else
(combs(array[1..-1], n-1).map{|comb| [array[0]] + comb} +
combs(array[1..-1], n))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment