diff options
-rw-r--r-- | test/ruby/test_sprintf_comb.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/test/ruby/test_sprintf_comb.rb b/test/ruby/test_sprintf_comb.rb index 0c28ba7027..ee748f765a 100644 --- a/test/ruby/test_sprintf_comb.rb +++ b/test/ruby/test_sprintf_comb.rb @@ -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 |