Skip to content

Instantly share code, notes, and snippets.

@shawn42
Created September 11, 2009 16:22
Show Gist options
  • Save shawn42/185395 to your computer and use it in GitHub Desktop.
Save shawn42/185395 to your computer and use it in GitHub Desktop.
lines = ["001002003004",
"005006007008"
]
map = []
lines.each do |line|
map << line
end
w = map[0].size/3
h = map.size
tiles = Array.new(w) do |x|
Array.new(h) do |y|
case map[y][x*3, 3]
when '001'
:one
when '002'
:two
when '003'
:three
when '004'
:four
when '005'
:five
when '006'
:six
when '007'
:seven
when '008'
:eight
else
nil
end
end
end
p tiles
=>
[[:one, :five], [:two, :six], [:three, :seven], [:four, :eight]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment