make combination recursionless.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-26 19:49:37 +00:00
parent f356662f6b
commit 7560adca78

View File

@ -107,15 +107,18 @@ class TestSprintfComb < Test::Unit::TestCase
VS.reverse! VS.reverse!
def combination(*args) def combination(*args)
if args.empty? args = args.map {|a| a.to_a }
yield [] i = 0
else while true
arg = args.shift n = i
arg.each {|v| as = []
combination(*args) {|vs| args.reverse_each {|a|
yield [v, *vs] n, m = n.divmod(a.length)
} as.unshift a[m]
} }
break if 0 < n
yield as
i += 1
end end
end end