Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 31, 2015 16:58
-
-
Save LyndseyWilliams/8016691 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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