Created
August 3, 2010 06:18
-
-
Save ecito/505934 to your computer and use it in GitHub Desktop.
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
continents = Hash.new | |
continents[:north_america] = [70, 10, -140, -60] | |
continents[:south_america] = [10, -60, -90, -30] | |
continents[:africa] = [40,-20, -20, 40] # <-- smaller, actual is --> [40, -40, -20, 50] | |
continents[:europe] = [70, 40, -10, 50] | |
#continents[:asia] = [80, -20, 50, 180] | |
def grid_up continent | |
grid = Array.new | |
continent[1].upto(continent[0]) do |h| | |
continent[2].upto(continent[3]) do |v| | |
grid.push [v, h, v + 10, h + 10] if h % 10 == 0 and v % 10 == 0 | |
end | |
end | |
grid | |
end | |
boxes = Array.new | |
continents.each_pair do |key,value| | |
grid_up(value).each do |grid| | |
boxes += grid if grid.size == 4 | |
end | |
end | |
puts "Number of boxes: #{boxes.size/4}" | |
puts "Boxes: #{boxes.inspect}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment