Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
A little bit complicated solution in Clear category for Xs and Os Referee by bityon
from itertools import product
def is_equal(lst, game_result):
return len(set([game_result[x][y] for x,y in lst])) == 1, game_result[lst[0][0]][lst[0][1]]
def get_first_equal(lst, game_result):
pos = [lst[0:3], lst[3:6], lst[6:], lst[::3], lst[1::3], lst[2::3], lst[::4], lst[2:-2:2]]
for l in pos:
res, val = is_equal(l, game_result)
if res and val != '.':
return val
return "D"
def checkio(game_result):
lst = list(product([0,1,2], [0,1,2]))
return get_first_equal(lst, game_result)
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"
Nov. 27, 2015
Comments: