What would be the correct translation of the following Python method to Ruby?
def uniqueCombinations(self, items, n):
"""
items: list of elements
n: number in a group
"""
if n == 0:
yield []
else:
for i in range(len(items)-n+1):
for cc in uniqueCombinations(items[i+1:],n-1):
yield [items[i]]+cc
What I want to do is call
uniqueCombinations(['01', '02', '03'], 2)
and get
[['01', '02'], ['01', '03'], ['02', '03']]
This is what I have so far.
def uniq_c(items, n)
if n == 0
yield []
else
puts items.inspect
range_max = items.length-n+1
for i in (0...range_max)
u = uniq_c(items[(i+1)..-1], n-1) { |x| x }
u.each do |cc|
yield [items[i]] + cc
end
end
end
end
but I get this:
in `+': can't convert Fixnum into Array (TypeError)