From 7560adca78aa58c46a6007a16d6413f3f075489b Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 26 Jan 2008 19:49:37 +0000 Subject: make combination recursionless. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_sprintf_comb.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'test/ruby/test_sprintf_comb.rb') 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 -- cgit v1.2.3