갑자기 한 번 짜봤는데 성능에는 문제가 많습니다.
그냥 combination 생성 함수를 재귀로 만들면 짧게 되는 지 보기 위해서...
module Combination
def self.generate(list, size)
if size == 1
list.map {|e| Array.new.push e }
else
total = Array.new
list.each do |x|
smaller_list = list - Array.new.push(x)
partial = self.generate(smaller_list, size-1).map do |y|
y.push x if y.last < x
end
total.concat partial.select {|z| not z.nil? }
end
total
end
end
end