Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First "Xs and Os Referee" solution in Clear category for Xs and Os Referee by uzodinmaforcun
from typing import List
def checkio(game_result: List[str]) -> str:
win1 = game_result[0][0] + game_result[1][1] + game_result[2][2]
win2 = game_result[0][0] + game_result[0][1] + game_result[0][2]
win3 = game_result[0][0] + game_result[1][0] + game_result[2][0]
win4 = game_result[1][0] + game_result[1][1] + game_result[1][2]
win5 = game_result[2][0] + game_result[2][1] + game_result[2][2]
win6 = game_result[2][0] + game_result[1][1] + game_result[0][2]
win7 = game_result[0][1] + game_result[1][1] + game_result[2][1]
win8 = game_result[0][2] + game_result[1][2] + game_result[2][2]
win_list = [win1, win2, win3, win4, win5, win5, win6, win7, win8]
for i in win_list:
if i == 'XXX':
return "X"
elif i == 'OOO':
return "O"
return "D"
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#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!")
Sept. 1, 2020
Comments: