Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:56
-
-
Save common-nighthawk/8965547 to your computer and use it in GitHub Desktop.
Revisions
-
common-nighthawk revised this gist
Feb 19, 2014 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -108,3 +108,10 @@ def get_diagonal(coord1, coord2) puts boggle_board1.board[1][3] # => returns "t" puts boggle_board1.board[2][0] # => returns "e" # REFLECTION # this was a really good challenge. i got a lot out of moving from the last exercise to this exercise-- # that is, transforming the boggle board to object oriented. also--getting the diagonal to print # out was a good task. i created if/else statements for the four starting points--not sure if there # is a more efficient way to do that. -
common-nighthawk revised this gist
Feb 13, 2014 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class BoggleBoard attr_reader :board def initialize(board) @board = board @@ -103,5 +103,8 @@ def get_diagonal(coord1, coord2) # create driver test code to retrieve a value at a coordinate here: puts boggle_board1.board[3][2] # => returns "k" puts boggle_board1.board[0][1] # => returns "r" puts boggle_board1.board[1][3] # => returns "t" puts boggle_board1.board[2][0] # => returns "e" -
common-nighthawk revised this gist
Feb 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def get_col(col) end def get_diagonal(coord1, coord2) if ((coord1[0]-coord2[0]).abs==@board.length-1)&&((coord1[1]-coord2[1]).abs==@board.length-1) diag = [] i = 0 -
common-nighthawk revised this gist
Feb 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def get_col(col) end def get_diagonal(coord1, coord2) if ((coord1[0]-coord2[0]).abs==@board.length-1)&&((coord1[1]-coord2[1]).abs==@board.length-1) diag = [] i = 0 -
common-nighthawk revised this gist
Feb 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def get_col(col) end def get_diagonal(coord1, coord2) if ((coord1[0]-coord2[0]).abs==@board.length-1)&&((coord1[1]-coord2[1]).abs==@board.length-1) diag = [] i = 0 -
common-nighthawk revised this gist
Feb 12, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def get_col(col) end def get_diagonal(coord1, coord2) if ((coord1[0]-coord2[0]).abs == @board.length-1) && ((coord1[1]-coord2[1]).abs == @board.length-1) diag = [] i = 0 -
common-nighthawk revised this gist
Feb 12, 2014 . 1 changed file with 87 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,61 @@ class BoggleBoard ## attr_accessor :board HELP--do not understand attr def initialize(board) @board = board end def create_word(*coords) coords.map { |coord| @board[coord.first][coord.last]}.join("") end def get_row(row) @board[row] end def get_col(col) column = [] i = 0 while i < @board.length column << @board[i][col] i +=1 end return column end def get_diagonal(coord1, coord2) if ( (coord1[0] - coord2[0]).abs == @board.length - 1 ) && ( (coord1[1] - coord2[1]).abs == @board.length-1 ) diag = [] i = 0 if coord1[0] == 0 && coord1[1] == 0 while i < @board.length diag << @board[i][i] i +=1 end elsif coord1[0] == 0 && coord1[1] == @board.length - 1 while i < @board.length diag << @board[i][@board.length - 1 - i] i +=1 end elsif coord1[0] == @board.length - 1 && coord1[1] == 0 while i < @board.length diag << @board[@board.length - 1 - i][i] i +=1 end else coord1[0] == @board.length - 1 && coord1[1] == @board.length - 1 while i < @board.length diag << @board[@board.length - 1 - i][@board.length - 1 - i] i +=1 end end return diag else puts "You did not enter diagonal coordinates." end end end @@ -10,11 +64,42 @@ class BoggleBoard ["e", "c", "l", "r"], ["t", "a", "k", "e"]] boggle_board1 = BoggleBoard.new(dice_grid) # implement tests for each of the methods here: puts boggle_board1.create_word([1,2], [1,1], [2,1], [3,2]) # => returns dock puts boggle_board1.create_word([2,1], [1,1], [1,2], [0,3]) == "code" puts boggle_board1.create_word([0,1], [0,2], [1,2]) == "rad" puts boggle_board1.create_word([3,3], [2,2], [3,2]) == "elk" puts boggle_board1.create_word([0,1], [1,1], [2,1], [3, 2]) == "rock" puts boggle_board1.create_word([2,1], [3, 1], [3,0]) == "cat" puts boggle_board1.get_row(0) == ["b", "r", "a", "e"] puts boggle_board1.get_row(1) == ["i", "o", "d", "t"] puts boggle_board1.get_row(2) == ["e", "c", "l", "r"] puts boggle_board1.get_row(3) == ["t", "a", "k", "e"] puts boggle_board1.get_col(0) == ["b", "i", "e", "t"] puts boggle_board1.get_col(1) == ["r", "o", "c", "a"] puts boggle_board1.get_col(2) == ["a", "d", "l", "k"] puts boggle_board1.get_col(3) == ["e", "t", "r", "e"] puts boggle_board1.get_row(0).join("") # => returns brae puts boggle_board1.get_row(1).join("") # => returns iodt puts boggle_board1.get_row(2).join("") # => returns eclr puts boggle_board1.get_row(3).join("") # => returns take puts boggle_board1.get_col(0).join("") # => returns biet puts boggle_board1.get_col(1).join("") # => returns roca puts boggle_board1.get_col(2).join("") # => returns adlk puts boggle_board1.get_col(3).join("") # => returns etre puts boggle_board1.get_diagonal([0,0], [3,3]) == ["b", "o", "l", "e"] puts boggle_board1.get_diagonal([3,3], [0,0]) == ["e", "l", "o", "b"] puts boggle_board1.get_diagonal([0,3], [3,0]) == ["e", "d", "c", "t"] puts boggle_board1.get_diagonal([3,0], [0,3]) == ["t", "c", "d", "e"] # create driver test code to retrieve a value at a coordinate here: -
dbc-challenges revised this gist
Oct 31, 2013 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,13 @@ class BoggleBoard ["e", "c", "l", "r"], ["t", "a", "k", "e"]] boggle_board = BoggleBoard.new(dice_grid) # implement tests for each of the methods here: # create driver test code to retrieve a value at a coordinate here: -
dbc-challenges created this gist
Oct 31, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class BoggleBoard #your code here 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)