Advertisement
saasbook

cartesian.rb

Jan 31st, 2012
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.27 KB | None | 0 0
  1. c = CartesianProduct.new([:a,:b], [4,5])
  2. c.each { |elt| puts elt.inspect }
  3. # [:a, 4]
  4. # [:a, 5]
  5. # [:b, 4]
  6. # [:b, 5]
  7.  
  8. c = CartesianProduct.new([:a,:b], [])
  9. c.each { |elt| puts elt.inspect }
  10. # (nothing printed since Cartesian product
  11. # of anything with an empty collection is empty)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement