Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MasonONeal/7764923 to your computer and use it in GitHub Desktop.
Save MasonONeal/7764923 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
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_row(row)
create_word([row,0], [row,1], [row,2], [row,3])
end
def get_col(col)
create_word([0,col], [1,col], [2,col], [3,col])
end
end
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
brae
iodt
eclr
take
biet
roca
adlk
etre
boggle_board = BoggleBoard.new(dice_grid)
# implement tests for each of the methods here:
puts boggle_board.create_word([0,0], [0,1], [0,2], [1,3]) #=> brat
puts boggle_board.get_row(0) #=> [b,r,a,e]
puts boggle_board.get_row(1) #=> [i,o.d.t]
puts boggle_board.get_row(2) #=> [e,c,l,r]
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]
puts boggle_board.get_col(3) #=> [e,t,r,e]
# Output:
# brae
# iodt
# eclr
# take *real word
# biet
# roca
# adlk
# etre
# create driver test code to retrieve a value at a coordinate here:
puts boggle_board.create_word([3,2])
# Part 5
I am still learning/curious about the limit of using only methods vs. defining a class for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment