Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
mybest solution in Speedy category for Xs and Os Referee by nennogabriel
def checkio(rows):
#based on Veky clear solution and gyhun_dash speed.
#the clear from veky is faster then gyhun,
#butcombine bouth reduce to half of time
inline = ''.join(rows)
diags = [inline[0:9:4], inline[2:7:2]]
cols = list(map(''.join, zip(*rows)))
lines = rows + list(cols) + list(diags)
return 'X' if ('XXX' in lines) else 'O' if ('OOO' in lines) else '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"
July 23, 2014
Comments: