Created
August 7, 2013 20:30
-
-
Save vjdhama/6178318 to your computer and use it in GitHub Desktop.
Edx Class 169.1x HW 1-7
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/env ruby | |
class CartesianProduct | |
include Enumerable | |
def initialize(array_a, array_b) | |
@cartesian_array = Array.new(0) | |
array_a.each do |element_a| | |
array_b.each do |element_b| | |
tmp_array = Array.new(0) | |
tmp_array.push(element_a,element_b) | |
@cartesian_array.push(tmp_array) | |
end | |
end | |
@cartesian_array | |
end | |
def each | |
@cartesian_array.each { |index| yield(index) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment