Advertisement
saasbook

Cartesian-product code for HW2

Jan 29th, 2012
11,514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.36 KB | None | 0 0
  1. class CartesianProduct
  2.   include Enumerable
  3.   # your code here
  4. end
  5.  
  6. c = CartesianProduct.new([:a,:b], [4,5])
  7. c.each { |elt| puts elt.inspect }
  8. # [:a, 4]
  9. # [:a, 5]
  10. # [:b, 4]
  11. # [:b, 5]
  12.  
  13. c = CartesianProduct.new([:a,:b], [])
  14. c.each { |elt| puts elt.inspect }
  15. # (nothing printed since Cartesian product
  16. # of anything with an empty collection is empty)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement