Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
December 28, 2015 09:19
-
-
Save Lydiakoller/7477978 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains 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) | |
@dice_grid = dice_grid | |
end | |
def create_word(board, *coords) | |
coords.map { |coord| board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
@dice_grid[row].join("") | |
end | |
def get_col(col) | |
@dice_grid.map {|c| c[col]}.join("") | |
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(dice_grid, [2,1], [1,1], [1,2], [0,3]) #=> returns "code" | |
puts boggle_board.create_word(dice_grid, [0,1], [0,2], [1,2]) #=> creates what california slang word? | |
puts boggle_board.create_word(dice_grid, [0,0],[0,1],[1,1],[0,2],[1,2]) #=> broad | |
puts boggle_board.create_word(dice_grid, [2,1],[3,1],[3,2],[3,3]) #=>cake | |
puts boggle_board.create_word(dice_grid, [3,2] #=> accesses just 'k' .. not sure if this was the intended way to access the specific coordinate | |
puts boggle_board.get_row(2) #=> ["i", "o", "d", "t"] | |
puts boggle_board.get_row(1) | |
puts boggle_board.get_row(3) #=> ["t", "a", "k","e"]) | |
puts boggle_board.get_col(0) #=> ["b","i", "e", "t"] | |
puts boggle_board.get_col(1) #=> ["r", "o", "c", "a"] | |
puts boggle_board.get_col(2) #=> ["a","d","l","k"] | |
# create driver test code to retrieve a value at a coordinate here: | |
puts boggle_board.create_word(dice_grid, [3,2]) #=> accesses just 'k' .. not sure if this was the intended way | |
#to access the specific coordinate? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment