Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LyndseyWilliams/8016691 to your computer and use it in GitHub Desktop.
Save LyndseyWilliams/8016691 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
@@dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
def create_word(*coords)
coords.map { |coord| @@dice_grid[coord.first][coord.last]}.join
end
def get_row(row)
return @@dice_grid[row]
end
def get_col(col)
result = []
@@dice_grid.each {|x| result.push(x[col])}
return result
end
def get_diagonal(
end
end
boggle = BoggleBoard.new
puts boggle.create_word([0,0], [1,1], [0,2], [0,1], [1,2]) #== "board"
puts boggle.create_word([3,0], [3,1], [2,1], [3,2], [2,2], [3,3]) #== "tackle"
puts boggle.create_word([0,0], [1,1], [0,2], [0,1], [1,2]) #== "board"
puts boggle.create_word([3,0], [3,1], [2,1], [3,2], [2,2], [3,3]) # == "tackle
print boggle.get_row(1) #=> ["i", "o", "d", "t"]
print "\n" #=> newline
print boggle.get_row(0)#=> ['b', 'r, 'a, 'e']
print "\n" #=> newline
print boggle.get_col(0)#=>['b','i', 'e', 't']
print "\n"
#Now print out all the rows and columns of the board as strings
print boggle.get_row(0) #=> brae
print "\n" #=> newline
print boggle.get_row(1)#=> iodt
print "\n" #=> newline
print boggle.get_row(2)#=> eclr
print "\n" #=> newline
print boggle.get_row(3)#=> take
print "\n" #=> newline
print boggle.get_col(0)#=> biet
print "\n" #=> newline
print boggle.get_col(1)#=> roca
print "\n" #=> newline
print boggle.get_col(2)#=> adlk
print "\n" #=> newline
print boggle.get_col(3)#=> etre
# create driver test code to retrieve a value at a coordinate here:
puts boggle.create_word([3,2]) #=> "k"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment