mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
f356662f6b
commit
7560adca78
1 changed files with 11 additions and 8 deletions
|
@ -107,15 +107,18 @@ class TestSprintfComb < Test::Unit::TestCase
|
|||
VS.reverse!
|
||||
|
||||
def combination(*args)
|
||||
if args.empty?
|
||||
yield []
|
||||
else
|
||||
arg = args.shift
|
||||
arg.each {|v|
|
||||
combination(*args) {|vs|
|
||||
yield [v, *vs]
|
||||
}
|
||||
args = args.map {|a| a.to_a }
|
||||
i = 0
|
||||
while true
|
||||
n = i
|
||||
as = []
|
||||
args.reverse_each {|a|
|
||||
n, m = n.divmod(a.length)
|
||||
as.unshift a[m]
|
||||
}
|
||||
break if 0 < n
|
||||
yield as
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue