Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lydiakoller/7477978 to your computer and use it in GitHub Desktop.
Save Lydiakoller/7477978 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@dice_grid = dice_grid
end
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last]}.join("")
end
def get_row(row)
@dice_grid[row].join("")
end
def get_col(col)
@dice_grid.map {|c| c[col]}.join("")
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)
puts boggle_board.create_word(dice_grid, [2,1], [1,1], [1,2], [0,3]) #=> returns "code"
puts boggle_board.create_word(dice_grid, [0,1], [0,2], [1,2]) #=> creates what california slang word?
puts boggle_board.create_word(dice_grid, [0,0],[0,1],[1,1],[0,2],[1,2]) #=> broad
puts boggle_board.create_word(dice_grid, [2,1],[3,1],[3,2],[3,3]) #=>cake
puts boggle_board.create_word(dice_grid, [3,2] #=> accesses just 'k' .. not sure if this was the intended way to access the specific coordinate
puts boggle_board.get_row(2) #=> ["i", "o", "d", "t"]
puts boggle_board.get_row(1)
puts boggle_board.get_row(3) #=> ["t", "a", "k","e"])
puts boggle_board.get_col(0) #=> ["b","i", "e", "t"]
puts boggle_board.get_col(1) #=> ["r", "o", "c", "a"]
puts boggle_board.get_col(2) #=> ["a","d","l","k"]
# create driver test code to retrieve a value at a coordinate here:
puts boggle_board.create_word(dice_grid, [3,2]) #=> accesses just 'k' .. not sure if this was the intended way
#to access the specific coordinate?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment