Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save awertman/9356438 to your computer and use it in GitHub Desktop.

Select an option

Save awertman/9356438 to your computer and use it in GitHub Desktop.

Revisions

  1. awertman revised this gist Mar 4, 2014. 1 changed file with 58 additions and 0 deletions.
    58 changes: 58 additions & 0 deletions 0.2.1-boggle_class_from_methods.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,37 @@
    class BoggleBoard

    #your code here
    class BoggleBoard

    def initialize(dice_grid)
    @dice_grid = dice_grid
    end

    def create_word(*grid)
    grid.map { |letter| @dice_grid[letter.first][letter.last] }.join("")
    end

    def get_row(row)
    @dice_grid[row-1].join("")
    end

    def get_col(column)
    @dice_grid.map { |row| row.slice(column-1) }.join("")
    end

    def get_coordinate(row,column)
    @dice_grid[row-1][column-1]
    end

    def get_diagonal(row,column)
    counter = 0
    diagonal = Array.new
    while row + counter <= 4 && column + counter <= 4
    diagonal << @dice_grid[row-1+counter][column-1+counter]
    counter +=1
    end
    return diagonal
    end

    end

    @@ -13,10 +44,37 @@ class BoggleBoard
    boggle_board = BoggleBoard.new(dice_grid)

    # implement tests for each of the methods here:
    puts boggle_board.get_row(1)
    puts boggle_board.get_col(1)
    puts boggle_board.get_row(2)
    puts boggle_board.get_col(2)
    puts boggle_board.get_row(3)
    puts boggle_board.get_col(3)
    puts boggle_board.get_row(4)
    puts boggle_board.get_col(4)

    # brae
    # biet
    # iodt
    # roca
    # eclr
    # adlk
    # take


    # create driver test code to retrieve a value at a coordinate here:

    puts boggle_board.create_word([1,2],[1,1],[2,1],[3,2]) == "dock"
    puts boggle_board.get_row(2) == "iodt"
    puts boggle_board.get_col(2) == "roca"
    puts boggle_board.get_coordinate(4,3) == "k"
    puts boggle_board.get_diagonal(1,2) == ["r","d","r"]


    # Reflection
    # good exercise in working with classes and objects. these are very comfortable topics for me. more importantly, this exercise
    # for me put some focus on nested arrays and how to access different elements. in reading about related topics,
    # it was interesting to learn that this is how many video games use positioning on a map, based on these types of
    # array coordinates.


  2. @dbc-challenges dbc-challenges revised this gist Oct 31, 2013. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion 0.2.1-boggle_class_from_methods.rb
    Original 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)
    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:



  3. @dbc-challenges dbc-challenges created this gist Oct 31, 2013.
    13 changes: 13 additions & 0 deletions 0.2.1-boggle_class_from_methods.rb
    Original 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)