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 rojeeer
def checkio(r):
n = len(r)
check_groups = [[r[x][y] for x in range(0, n)] for y in range(0, n)] +\
[[r[x][y] for y in range(0, n)] for x in range(0, n)] +\
[[r[x][y] for x in range(0, n) for y in range(0, n) if x == y]] +\
[[r[x][y] for x in range(0, n) for y in range(0, n) if x + y == n - 1]]
for group in check_groups:
if group[0] != '.' and len(set(group)) == 1:
return group[0]
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"
Nov. 16, 2015
Comments: