Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatrubylove/6468d5a0c35968519c8c to your computer and use it in GitHub Desktop.
Save thatrubylove/6468d5a0c35968519c8c to your computer and use it in GitHub Desktop.
bingo grader bitches
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