Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sjafri5/8744836 to your computer and use it in GitHub Desktop.
Save sjafri5/8744836 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class Boggle
def initialize(board)
@board = board
end
def get_letter(row, col)
@board[row][col]
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_row(row)
@board[row].inspect
end
def get_column(column)
column_array = Array.new
@board.each { |e| column_array.push(e[column]) }
column_array.inspect # Remove #inspect to see as a column.
end
end
# implement tests for each of the methods here:
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
boggle_board = Boggle.new(dice_grid)
# implement tests for each of the methods here:
puts "=========="
puts boggle_board.get_letter(0, 0) == "b"
puts boggle_board.create_word([0, 0], [0, 1], [1, 1]) == "bro"
puts boggle_board.get_row(0) == ["b", "r", "a", "e"]
puts boggle_board.get_column(0) == ["b", "i", "e", "t"]
# create driver test code to retrieve a value at a coordinate here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment