Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
model the field like a numpad solution in Clear category for Xs and Os Referee by leggewie
from typing import List
def checkio(game_result: List[str]) -> str:
# enumerate winning combinations
# slots are numbered analog to the keys on a calculator or numpad
wins = ([1,2,3],[4,5,6],[7,8,9], # horizontal
[1,4,7],[2,5,8],[3,6,9], # vertical
[1,5,9],[3,5,7]) # diagonal
# initialize variables
field={}
winner = "D"
# read the values in
for y in range(3):
for x in range(3):
field[y*3+x+1] = game_result[y][x]
for win in wins:
a, b, c = win
if field[a] == field[b] == field[c] and not field[a] == ".":
winner = field[a]
break
return winner
June 1, 2021
Comments: