Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save genevievebelle/9868850 to your computer and use it in GitHub Desktop.
Save genevievebelle/9868850 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@boggle_board = dice_grid
end
def create_word(*coords)
coords.map { |coord| @boggle_board[coord.first][coord.last]}.join("")
end
# def possible_word?("word") #aborted attempt to write method to see if a particular word is possible in given board
# "word".split(" ")map{|x| x.to_i
# @boggle_board.include?(i)
# end
def get_row(row)
@boggle_board[row]
end
def get_col(col)
@boggle_board.transpose[col]
end
# def get_diagonal(starting_col) #I couldn't get this bonus challenge to work ...
# raise ArgumentError "not a valid diagonal" unless starting_col == 0 || starting_col == 3
# result = []
# a = starting_col #diagonal will run from a-b
# b = 0
# 4.times do
# if starting_col == 3 #from the upper-right corner
# a -= 1
# b += 1
# else # from upper-left corner
# b = a += 1
# 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:
puts board.get_diagonal(0)
puts possible_word(let) == true
puts board.create_word([2,1], [1,1], [1,2], [0,3]) == "code"
puts board.create_word([0,0], [1,0], [3,2], [3,3]) == "bike"
puts board.create_word([1,2], [1,1], [0,1], [3,2]) == "dork"
puts board.create_word([2,0], [2,1], [2,2], [0,2], [1,0], [2,3]) == "eclair"
puts board.get_row(1) == ["i", "o", "d", "t"]
# create driver test code to retrieve a value at a coordinate here:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment