Skip to content

Instantly share code, notes, and snippets.

@MattRoelle
Created February 18, 2013 19:43
Show Gist options
  • Save MattRoelle/4980055 to your computer and use it in GitHub Desktop.
Save MattRoelle/4980055 to your computer and use it in GitHub Desktop.
class TwoDimensionalArray
attr_accessor :map
def initialize w, h
@w = w
@h = h
self.map = []
(0...w).each do |x|
(0...h).each do |y|
map[(x*@w) + y] = nil
end
end
end
def set x, y, val
self.map[(x*@w) + y] = val
end
def get x, y
self.map[(x*@w) + y]
end
end
test = TwoDimensionalArray.new(10,10)
(0...10).each do |x|
(0...10).each do |y|
test.set x, y, "(#{x},#{y})"
end
end
puts test.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment