Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Xs and Os Referee by krzysztofc10
#set X and O
def checkio(game_result):
x = set(['X'])
o = set(['O'])
def win(portion):
if portion == x:
return "X"
elif portion == o:
return "O"
for row in game_result:
row = set(row)
result = win(row)
if result is not None:
return result
for column in zip(*game_result):
column = set(column)
result = win(column)
if result is not None:
return result
diagonal = set([game_result[i][i] for i in range(3)])
inv_diagonal = set([game_result[i][2-i] for i in range(3)])
result = win(diagonal)
if result is not None:
return result
result = win(inv_diagonal)
if result is not None:
return result
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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Jan. 16, 2018