Created
August 13, 2011 11:49
-
-
Save jokester/1143767 to your computer and use it in GitHub Desktop.
求数组{ (0..N1),{0..N2},...,(0..Nn) }的笛卡尔积
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
puts "input N" | |
i=gets.to_i | |
m=[1] | |
1.upto i do |j| | |
puts "input N#{j}" | |
k=gets.to_i | |
m.unshift m[0]*(k+1) | |
end | |
0.upto m[0]-1 do |j| | |
o=[] | |
1.upto(i) do |k| | |
o.unshift (j%m[k-1])/m[k] | |
end | |
p o | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby 里面自带了计算笛卡尔积的方法
["a","b"].product ["c","d"]