Skip to content

Instantly share code, notes, and snippets.

@ecito
Created August 3, 2010 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecito/505934 to your computer and use it in GitHub Desktop.
Save ecito/505934 to your computer and use it in GitHub Desktop.
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