![]() new ( * ) end def index ( row_or_pos, column = nil ) if column row_or_pos * + column else row_or_pos end end def at ( position ) row = position / col = position % end def ( row_or_pos, column = nil ) end #. module WordSearch class Grid attr_reader :rows, :columns, :size def initialize ( rows, columns, grid = nil ), = rows, columns = * = grid || Array. This way I can represent each location as a single integer, which is cleaner than trying to juggle (row, column) tuples. Since the algorithm requires that I be able to try a word against every possible location in the grid, I chose to implement the grid as a one-dimensional array. Visually, it’s a two-dimensional grid of rows and columns: grid = WordSearch :: Grid. The first thing to do was to represent the grid itself. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |