Skip to content

Instantly share code, notes, and snippets.

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 brittanmcg/8142558 to your computer and use it in GitHub Desktop.
Save brittanmcg/8142558 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize
@dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
end
def words(*coords)
coords.map do |coord|
@dice_grid[coord.first][coord.last]
end.join("")
end
def get_row(row_num)
@dice_grid[row_num]
end
def get_col(col_num)
@dice_grid.map {|e| e[col_num] }
end
def get_char(*coords)
coords.map do |coord|
@dice_grid[coord.first][coord.last]
end
end
def get_diag(*first_coord)
@dice_grid.map {|diag_coord| diag_coord[first_coord.first][first_coord.last] }
first_coord.first += 1
first_coord.last += 1
until first_coord == last_coord
end
end
end
game = BoggleBoard.new
p game.words([0,1],[0,2],[2,1])
p game.get_row(2)
p game.get_col(1)
p game.get_char([2,1])
p game.get_diag([0,0],[3,3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment