Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Xs and Os Referee by apex123
def checkio(board):
#check for horizontal winners
for row in board:
if row[0] == row[1] == row[2] and '.' not in row:
return row[1]
#check for vertical winners
for col in zip(*board):
if col[0] == col[1] == col[2] and '.' not in col:
return col[1]
#check for diagonal winners
if (board[0][0] == board[1][1] == board[2][2] or \
board[0][2] == board[1][1] == board[2][0]) and \
board[1][1] != '.':
return board[1][1]
return 'D'
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
assert checkio([
"O.X",
"XX.",
"XOO"]) == "X", "Xs wins again"
Feb. 15, 2015
Comments: