Skip to content

Instantly share code, notes, and snippets.

@ColinDKelley
Created March 9, 2015 15:27
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 ColinDKelley/fd97b73e9ef8772e1a7e to your computer and use it in GitHub Desktop.
Save ColinDKelley/fd97b73e9ef8772e1a7e to your computer and use it in GitHub Desktop.
tiles = {}
STDIN.readlines.map.with_index do |line, y|
x = 0
line.chomp.split(".").each do |segment|
unless segment.empty?
tile = [x, segment.size, segment[0]]
if value = tiles[tile]
tiles[tile] = [value.first, value.last + 1]
else
tiles[tile] = [y, 1]
end
end
x += segment.size + 1
end
end
tiles.sort_by { |(x, _, _), (y, _)| [x, y] }.each do |(x, width, character), (y, height)|
puts "(#{width}x#{height}) tile of character '#{character}' located at (#{x},#{y})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment