Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save case-eee/9095424 to your computer and use it in GitHub Desktop.
Save case-eee/9095424 to your computer and use it in GitHub Desktop.
Boggle Class Challenge
class BoggleBoard
def initialize(boggle_board)
@boggle_board = boggle_board
end
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last]}.join("")
end
def get_row(row)
return @boggle_board[(row)]
end
def get_col(col)
return @boggle_board.map {|r| r[col]}
end
end
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
new_boggle = BoggleBoard.new(dice_grid)
p new_boggle.create_word(dice_grid, [1,2], [1,1], [2,1], [3,2]) #=> returns "dock"
p new_boggle.create_word(dice_grid, [2,1], [1,1], [1,2], [0,3]) #=> returns "code"
p new_boggle.create_word(dice_grid, [0,1], [0,2], [1,2]) #=> returns "rad"
p new_boggle.create_word(dice_grid, [0,0], [1,0], [0,1], [1,2]) #=> returns "bird"
p new_boggle.create_word(dice_grid, [2,1], [1,1], [2,2], [1,2]) #=> returns "cold"
p new_boggle.get_col(1) == ["r", "o", "c", "a"] #=> true
p new_boggle.get_col(0) == ["b", "i", "e", "t"] #=> true
p new_boggle.get_col(3) == ["e", "t", "r", "e"] #=> true
p new_boggle.get_row(1) == ["i", "o", "d", "t"] #=> true
p new_boggle.get_row(3) == ["t", "a", "k", "e"] #=> true
p new_boggle.get_row(0) == ["b", "r", "a", "t"] #=> false
p dice_grid[0][1] == "r" #=> should be true
p dice_grid[2][1] == "c" #=> should be true
p dice_grid[3][3] == "e" #=> should be true
p dice_grid[2][3] == "x" #=> should be false
# Reflection
# I really enjoyed working on this challenge. It was an equal amount of challenging but also used what I knew already. I
# like how it built off previous challenges. I also spent some time before working on this challenge going through
# Object Oriented Programming tutorials, which made this challenge easier. I still can't figure out how to create the
# get_diagonal method (but perhaps by reading others' code, I'll be able to figure it out!).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment