Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChasevanHekken/9178803 to your computer and use it in GitHub Desktop.
Save ChasevanHekken/9178803 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
attr_accessor :board
def initialize(board)
@board = board
end
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last]}.join("")
end
def get_row(board, row)
board[row].join("")
end
def get_column(board, col)
arr = []
i = 0
board[col].count.times do
arr << board[i][col]
i = i + 1
end
return arr.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, [3,2],[3,1],[3,0],[2,0]) == "kate"
puts boggle_board.get_column(dice_grid, 0) == "biet"
puts boggle_board.get_column(dice_grid, 1) == "roca"
puts boggle_board.get_column(dice_grid, 2) == "adlk"
puts boggle_board.get_column(dice_grid, 3) == "etre"
puts boggle_board.get_row(dice_grid, 0) == "brae"
puts boggle_board.get_row(dice_grid, 1) == "iodt"
puts boggle_board.get_row(dice_grid, 2) == "eclr"
puts boggle_board.get_row(dice_grid, 3) == "take"
puts boggle_board.create_word(dice_grid, [1,2]) == "d"
puts boggle_board.create_word(dice_grid, [3,2],[3,1],[3,0],[2,0]) == "kate"
# Reflect:
# Object oriented programming allows you to create many objects/instances of classes, which allows you re-use
# various data structures and algorithms.
#
#
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment