Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nairys/9218705 to your computer and use it in GitHub Desktop.
Save nairys/9218705 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(grid)
@grid = grid
end
def create_word(*coords)
puts coords.map { |coord| @grid[coord.first][coord.last]}.join("")
end
def get_row(row)
puts @grid[row]
end
def get_col(col)
col_array = []
@grid.length.times do |x|
col_array << @grid[x][col]
end
puts col_array
end
def get_coord(row, col)
puts @grid[row][col]
end
end
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
boggle_board = BoggleBoard.new(dice_grid)
# implement tests for each of the methods here:
boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) #=> returns "code"
boggle_board.get_row(1) #=> ["i", "o", "d", "t"]
boggle_board.get_col(2) #=> ["a", "d", "l", "k"]
# create driver test code to retrieve a value at a coordinate here:
boggle_board.get_coord(3,2) #=> returns "k"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment