Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test gf markdown
module BingoGrader
  extend self

  def bingo?(board)
    bingo_via_row?(board)             ||
      bingo_via_row?(board.transpose) ||
      bingo_via_diag?(board)          ||
      bingo_via_diag?(board.reverse)
  end

private

  #solves the horizontal problem. Enemerable madness.
  def bingo_via_row?(board)
    board.map do |row|
      row.all? {|v| v == 0 }
    end.any?
  end

  def bingo_via_diag?(board)
    size = board[0].count
    (0..size-1).map {|n| board[n][n] }.all? {|v| v == 0 }
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.