Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 27, 2015 13:09
-
-
Save mechamanny/7330936 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 | |
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 get_col(col) | |
col_array= @boggle_board.map{ |x| x[col] } | |
print col_array | |
end | |
def get_row(row) | |
row_array = @boggle_board[row] | |
print row_array | |
end | |
end | |
#def get_diagonal(coord1, coord2) | |
# [1,2] = d [2,1] = c | |
# + row + col | |
# - row + col | |
# - row - col | |
# + row - col | |
#if coord1[x,y] == coord2[x + 1, y- 1] || | |
#coord1[x,y] == coord2[x - 1, y + 1] || | |
#coord1[x,y] == coord2[x - 1, y- 1] || | |
#coord1[x,y] == coord2[x + 1, y+ 1] | |
# diag= [coord1] | |
# if coord1[x,y] == coord2[x +- 1, y -+ 1] | |
# diag << coord2 | |
# while coord1[x,y] == coord2[x +- 2, y -+ 2] | |
# diag << coord2 | |
# else if coord1[x,y] == coord2[x +- 3, y -+ 3] | |
# 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) # instantiate a boggle board by calling the class BoggleBoard.new, using the dice_grid as the argument | |
# implement tests for each of the methods here: | |
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? rad! | |
puts boggle_board.create_word( [0.0], [0,1], [1,1], [2,1], [3,2],[3,3], [2,3]) #= brocker | |
puts boggle_board.create_word( [2,2], [1,1], [0,0]) #= creates lob | |
boggle_board.get_col(0) #= [b,i,e,t] | |
boggle_board.get_col(1) #= [r,o,c,a] | |
boggle_board.get_col(2) #= [a,d,l,k] | |
boggle_board.get_row(0) #= [b,r,a,e] | |
boggle_board.get_row(1) #= [i,o.d.t] | |
boggle_board.get_row(2) #= [e,c,l,r] | |
# create driver test code to retrieve a value at a coordinate here: | |
puts boggle_board.create_word([3,2]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment