Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:56
-
-
Save jcohen10/9163611 to your computer and use it in GitHub Desktop.
Revisions
-
jcohen10 revised this gist
Feb 24, 2014 . 1 changed file with 4 additions and 4 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 @@ -13,7 +13,7 @@ def get_row(row) end def get_col(col) print @dice_grid.transpose[col].join("") end end @@ -45,8 +45,8 @@ def get_col(col) # Reflection # Object oriented programming feels a bit more organized to me than procedural # programming - more structured and easier to edit. # The prior practice with setting up classes and using driver tests helped make this # one feel like a pretty straightforward exercise. -
jcohen10 revised this gist
Feb 23, 2014 . 1 changed file with 17 additions and 32 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,41 +1,20 @@ class BoggleBoard def initialize(dice_grid) @dice_grid = dice_grid end def create_word(board, *coords) coords.map { |coord| board[coord.first][coord.last]}.join("") end def get_row(row) print @dice_grid[row].join("") # 'join' to return as a string. end def get_col(col) print @dice_grid.transpose[col].join("") end end @@ -53,6 +32,7 @@ def get_col(col) puts boggle_board.get_row(1) puts boggle_board.get_row(2) puts boggle_board.get_row(3) # returns 'take' - the only real word here puts boggle_board.get_col(0) puts boggle_board.get_col(1) puts boggle_board.get_col(2) @@ -63,5 +43,10 @@ def get_col(col) puts boggle_board.create_word(dice_grid, [3,2]) # returns 'k' # Reflection # Object oriented programming feels a bit more organized to me than procedural # programming - more structured, and therefore easier to edit. # Last week's exercises using classes and driver code helped in setting up this # code. -
jcohen10 revised this gist
Feb 23, 2014 . 1 changed file with 50 additions and 5 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,22 +1,67 @@ class BoggleBoard def initialize(dice_grid) @dice_grid = dice_grid end def create_word(board, *coords) coords.map { |coord| board[coord.first][coord.last]}.join("") end def get_row(row) case row when 0 print @dice_grid[0].join("") # the #join method returns it as a string when 1 print @dice_grid[1].join("") when 2 print @dice_grid[2].join("") when 3 print @dice_grid[3].join("") end end def get_col(col) case col when 0 print @dice_grid.transpose[0].join("") when 1 print @dice_grid.transpose[1].join("") when 2 print @dice_grid.transpose[2].join("") when 3 print @dice_grid.transpose[3].join("") end 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) # implement tests for each of the methods here: puts boggle_board.create_word(dice_grid, [1, 2], [1, 1], [2, 1], [3, 2]) == "dock" # returns true puts boggle_board.get_row(0) puts boggle_board.get_row(1) puts boggle_board.get_row(2) puts boggle_board.get_row(3) # returns 'take' - the only real word here puts boggle_board.get_col(0) puts boggle_board.get_col(1) puts boggle_board.get_col(2) puts boggle_board.get_col(3) # create driver test code to retrieve a value at a coordinate here: puts boggle_board.create_word(dice_grid, [3,2]) # returns 'k' -
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)