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 sion
def checkio(game_result):
rPattern = createPattern(game_result)
for i in rPattern:
for s in "XO":
if i.count(s) == 3 :
return s
return "D"
def createPattern(game_result):
list =[]
#horizontal pattern
list.extend(game_result)
#vertical pattern
for i in range(0,3):
pat = ""
for res in game_result:
pat +=res[i]
list.append(pat)
#cross pattern
list.append(game_result[0][0]+game_result[1][1]+game_result[2][2])
list.append(game_result[0][2]+game_result[1][1]+game_result[2][0])
return list
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([
"X.O",
"XX.",
"XOO"]) == "X", "Xs wins"
assert checkio([
"OO.",
"XOX",
"XOX"]) == "O", "Os wins"
assert checkio([
"OOX",
"XXO",
"OXX"]) == "D", "Draw"
Feb. 15, 2014
Comments: