Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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