Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lee-sh-roy/7544020 to your computer and use it in GitHub Desktop.
Save lee-sh-roy/7544020 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
def initialize(board)
@b_board = board
end
def create_word(*coords)
coords.map { |coord| @b_board[coord.first][coord.last]}.join("")
end
def get_row(row)
@b_board[row]
end
def get_col(col)
@b_board.transpose[col]
end
def get_coord(row, col)
@b_board[row][col]
end
def print
0..@b_board.length.times do |x|
puts get_row(x).join
puts get_col(x).join
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)
# implement tests for each of the methods here:
p boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) #=> returns "dock"
p boggle_board.create_word([2,2], [3,1], [2,1], [3,2]) #=> returns "lack"
p boggle_board.create_word([0,1], [1,1], [2,1], [3,2]) #=> returns "rock"
p boggle_board.get_row(1) #=> returns ["i", "o", "d", "t"]
p boggle_board.get_row(3) #=> returns ["t", "a", "k", "e"]
p boggle_board.get_col(2) #=> returns ["a", "d", "l", "k"]
p boggle_board.get_col(3) #=> returns ["e", "t", "r", "e"]
boggle_board.print #=> returns brae
# biet
# iodt
# roca
# eclr
# adlk
# take
# etre
# create driver test code to retrieve a value at a coordinate here:
p boggle_board.get_coord(1,3) #=> returns "t"
p boggle_board.get_coord(0,2) #=> returns "a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment