Last active
August 29, 2015 14:22
-
-
Save thatrubylove/6468d5a0c35968519c8c to your computer and use it in GitHub Desktop.
bingo grader bitches
This file contains 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 characters
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