Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save estensland/7712693 to your computer and use it in GitHub Desktop.
Save estensland/7712693 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
#your code here
class BoggleBoard
def initialize (input)
@board = input
end
def create_word(*coords)
coords.map { |coord| @board[coord.first][coord.last]}.join("")
end
def get_row(row)
@board[row]
end
def get_col(col)
@board.transpose[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 dice_grid[0][1] == "r" # Changed to dice_grid to reflect the change to a class
puts dice_grid[2][1] == "c"
puts dice_grid[3][3] == "e"
puts dice_grid[2][3] != "x"
puts boggle_board.create_word( [2,1], [1,1], [1,2], [0,3]) == "code" # Added boggle_board to reflect the change to a class
puts boggle_board.create_word([0,1], [0,2], [1,2]) == "rad"
puts boggle_board.create_word( [0,0], [0,1], [1,0], [2,1], [3,2]) == "brick"
puts boggle_board.create_word( [1,2], [0,2], [0,1], [3,2]) == "dark"
puts boggle_board.get_row(1) == ["i", "o", "d", "t"]
print boggle_board.get_col(1) == ["r", "o", "c", "a"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment