Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Size_independent solution in Creative category for Xs and Os Referee by Zyzlik
# migrated from python 2.7
from itertools import islice
def checkio(game_result):
# independent of the size
length = len(game_result)
# check horizontal
for row in game_result:
if row == 'X' * length or row == "O" * length:
return row[0]
# check vertical
combination = ''
for i in range(length):
for k in range(length):
combination += game_result[k][i]
if combination == 'X' * length or combination == 'O' * length:
return combination[0]
else:
combination = ''
# check diagonal
for i in range(length):
combination += game_result[i][i]
if combination == 'X' * length or combination == 'O' * length:
return combination[0]
else:
combination = ''
k = 0
for i in range(length-1,-1,-1):
combination += game_result[k][i]
k += 1
if combination == 'X' * length or combination == 'O' * length:
return combination[0]
return 'D'
Aug. 14, 2015