kucheasysa

Algoverse_adesh_29

Jun 27th, 2024
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. class Solution:
  2.     def tictactoe(self, moves: List[List[int]]) -> str:
  3.  
  4.         table = [[0] * 3 for _ in range(3)]
  5.  
  6.         i = 0
  7.         while i < len(moves):
  8.             x = moves[i][0]
  9.             y = moves[i][1]
  10.             if i % 2 == 0:
  11.                 table[x][y] = 7
  12.             else:
  13.                 table[x][y] = 5
  14.             i += 1
  15.  
  16.         print(table)
  17.         for i in range(len(table)):
  18.             if sum(table[i]) == 21:
  19.                 return "A"
  20.             elif sum(table[i]) == 15:
  21.                 return "B"
  22.  
  23.         for j in range(3):
  24.             s = 0
  25.             for i in range(3):
  26.                 s = s + table[i][j]
  27.             if s == 21:
  28.                 return "A"
  29.             elif s == 15:
  30.                 return "B"
  31.  
  32.         i = 0
  33.         j = 0
  34.         s = 0
  35.         while i < len(table) and j < len(table[0]):
  36.             s += table[i][j]
  37.             i += 1
  38.             j += 1
  39.         if s == 21:
  40.             return "A"
  41.         if s == 15:
  42.             return "B"
  43.  
  44.         i = 0
  45.         j = 2
  46.         s = 0
  47.         while i < 3 and j >= 0:
  48.             s += table[i][j]
  49.             i += 1
  50.             j -= 1
  51.  
  52.         if s == 21:
  53.             return "A"
  54.         if s == 15:
  55.             return "B"
  56.  
  57.         if len(moves) == 9:
  58.             return "Draw"
  59.  
  60.         return "Pending"
  61.  
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment