diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-26 19:49:37 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-26 19:49:37 +0000 |
| commit | 3a5d0b00d1fd48aa6547aaa3737a2bb2ae385021 (patch) | |
| tree | 44194d7503da3e4903a32c1c536e209557f3f2f5 /test/ruby | |
| parent | c5498be6d69d80e6970ecbc0bcc4251b6ebf6668 (diff) | |
| download | ruby-3a5d0b00d1fd48aa6547aaa3737a2bb2ae385021.tar.gz ruby-3a5d0b00d1fd48aa6547aaa3737a2bb2ae385021.tar.xz ruby-3a5d0b00d1fd48aa6547aaa3737a2bb2ae385021.zip | |
make combination recursionless.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
| -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 0c28ba702..ee748f765 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 |
