Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Itertools.chain zip and count solution in Creative category for Xs and Os Referee by lezeroq
from itertools import chain
def checkio(g):
for l in chain(g, zip(*g), zip(*[(g[i][i], g[i][2-i]) for i in range(3)])):
if l.count(l[0]) == 3 and l[0] != '.':
return l[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"
May 4, 2015
Comments: