Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andrewhouse/8233241 to your computer and use it in GitHub Desktop.

Select an option

Save andrewhouse/8233241 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(board)
@board = board
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_row(row)
@board.each_index do |index|
return @board[index] if index == row
end
end
def get_col(col)
@board.each_index do |index|
@board.each_index do |index2|
if col == index2
return @board[col]
end
end
end
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([0,1], [1,1], [1,2])
puts boggle_board.get_row(1)
puts boggle_board.get_col(3)
#after filling in the area for the previous challenge, this was much more simple.
#just adding in a class and changing the driver code, it will make for future boards to be much easier to be called this way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment