Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Created
March 11, 2014 04:29
-
-
Save arieldiamond/9479536 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle 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(board) | |
if board.length != 4 | |
raise "Wrong type of board!" | |
else | |
@board = board | |
end | |
end | |
def create_word(*coords) | |
puts coords.map { |coord| @board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
p @board[row] | |
end | |
def get_col(col) | |
p @board.transpose[col] | |
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) | |
boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) # => code | |
boggle_board.create_word([3,2]) # => k | |
boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) # => dock | |
boggle_board.create_word([3,0], [3,1], [3,2], [3,3]) # => take | |
boggle_board.create_word([2,1], [3,1], [3,2], [3,3]) # => cake | |
boggle_board.get_row(1) # => ["i", "o", "d", "t"] | |
boggle_board.get_col(0) # => ["b", "i", "e", "t"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment