Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Compare sets of positions solution in Clear category for Xs and Os Referee by kudinov.feodor
from typing import List
def checkio(game_result: List[str]) -> str:
game_result_str = "".join(game_result)
success_res = [
"048", "246", # diagonals
"012", "345", "678", # horizontals
"036", "147", "258" # verticals
]
for sign in ["X", "O"]:
positions = {str(_idx) for _idx, i in enumerate(game_result_str) if i == sign}
if any(set(res) <= positions for res in success_res):
return sign
return "D"
if __name__ == '__main__':
print("Example:")
print(checkio(["X.O",
"XX.",
"XOO"]))
#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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Sept. 21, 2019
Comments: