Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shidel-dev/7400908 to your computer and use it in GitHub Desktop.
Save shidel-dev/7400908 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[row]
end
def get_col(col)
column=[]
@board.each{|a| column.push(a[col])}
return column
end
def get_diagonal(first,last)
diagonal=[]
if last[0]-first[0] != last[1]-first[1] then raise "not a diagonal" end
for i in first[0]..last[0]
diagonal.push(@board[i][first[1]+i])
end
diagonal
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([2,1], [1,1], [1,2], [0,3]) #=> returns "code"
puts boggle_board.create_word([0,1], [0,2], [1,2]) #=> creates what california slang word?
puts boggle_board.create_word([2,0], [3,1], [3,0])
puts boggle_board.create_word([2,1], [3,1], [3,0])
puts boggle_board.get_row(1) #=> ["i", "o", "d", "t"]
puts boggle_board.get_col(1) #=> ["r", "o", "c", "a"]
puts boggle_board.get_diagonal([0,0],[3,3])
puts boggle_board.get_diagonal([0,0],[3,2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment