Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Created June 9, 2015 04:39
Show Gist options
  • Save thatrubylove/9020555f33434758c755 to your computer and use it in GitHub Desktop.
Save thatrubylove/9020555f33434758c755 to your computer and use it in GitHub Desktop.
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