Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:57
-
-
Save ahardy55/9369121 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
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
class BoggleBoard | |
def create_word(board, *coords) | |
coords.map { |coord| board[coord.first][coord.last]}.join("") | |
end | |
def get_row(board, row) | |
board[row] | |
end | |
def get_col(board, col) | |
board.collect{|row| row[col]} | |
end | |
end | |
boggle_board = BoggleBoard.new | |
puts boggle_board.create_word(dice_grid, [1,2], [1,1], [2,1], [3,2]) == "dock" | |
puts boggle_board.get_row(dice_grid, (0)) == ["b", "r", "a", "e"] | |
puts boggle_board.get_row(dice_grid, (1)) == ["i", "o", "d", "t"] | |
puts boggle_board.get_row(dice_grid, (2)) == ["e", "c", "l", "r"] | |
puts boggle_board.get_row(dice_grid, (3)) == ["t", "a", "k", "e"] | |
puts boggle_board.get_col(dice_grid, (0)) == ["b", "i", "e", "t"] | |
puts boggle_board.get_col(dice_grid, (1)) == ["r", "o", "c", "a"] | |
puts boggle_board.get_col(dice_grid, (2)) == ["a", "d", "l", "k"] | |
puts boggle_board.get_col(dice_grid, (3)) == ["e", "t", "r", "e"] | |
=begin | |
Total Output : | |
["b", "r", "a", "e"] | |
["i", "o", "d", "t"] | |
["e", "c", "l", "r"] | |
["t", "a", "k", "e"] | |
["b", "i", "e", "t"] | |
["r", "o", "c", "a"] | |
["a", "d", "l", "k"] | |
["e", "t", "r", "e"] | |
=end | |
# create driver test code to retrieve a value at a coordinate here: | |
puts boggle_board.create_word(dice_grid, [3,2]) == "k" | |
=begin | |
Reflection: Utilizing the object oriented seems extremely helpful in organizing the code, and in this case, didn't add any | |
additional difficulity to the exercise. In a larger batch of code, it would be indespensible. Additional classes could be added | |
organize the data. | |
This particular exercise didn't actually provide as much challenge as I hoped, it was essentially the same as the previous | |
one, just with a class thrown in. Due to time constraints, I didn't have time to tackle the diagonal, but it seems like a very | |
interesting challenge to explore when I get caught up. | |
=end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment