RosettaCodeData/Task/Combinations/Ruby/combinations.rb
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

5 lines
183 B
Ruby

def comb(m, n)
(0...n).to_a.combination(m).to_a
end
comb(3, 5) # => [[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]