Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 2, 2016 15:29
-
-
Save jaybobo/8324161 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 | |
attr_reader :board | |
def initialize(board) | |
@board = board | |
end | |
#your code here | |
def create_word(*coords) | |
coords.map {|coord| board[coord.first][coord.last]}.join("") | |
end | |
def get_row(rnum) | |
board[rnum] | |
end | |
def get_col(cnum) | |
array = [] | |
(0..board.length-1).each {|x| array << board[x][cnum]} | |
array | |
end | |
def get_diagonal(start,ending) | |
#x = 0 #add one until x == y | |
array = [] | |
#until start.first == ending.first #until the indexes are the same (e.g. 0 = 0) | |
(board.length).times do |x| | |
array << board[start.first + x][start.last + x] | |
end | |
array.inspect | |
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([1,1], [2,1], [3,2]) | |
puts boggle_board.get_row(0).inspect | |
puts boggle_board.get_col(1).inspect | |
puts dice_grid[3][2] | |
puts boggle_board.get_diagonal([0,0],[3,3]) | |
puts boggle_board.get_diagonal([0,1],[2,3]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment