The TransCompilator

Solved LeetCode program · 916 of 1,000

#1275 · Find Winner on a Tic Tac Toe Game

Easy Array chunk-19.md

Original English source

The moves is a list of 0, 0, 2, 0, 1, 1, 2, 1, 2, 2, 1, 0, 0, 1, 0, 2, and 1, 2. The board is a list of 9 zeros. The winner is 0. The turn is 0.
Repeat while turn is at most 8 and winner is 0.
The row is item (turn times 2) of moves. The column is item (turn times 2 plus 1) of moves. The mark is 1. If turn modulo 2 is 1, set mark to 2. Set item (row times 3 plus column) of board to mark. If item 0 of board is item 1 of board and item 1 of board is item 2 of board and item 0 of board is not 0, set winner to item 0 of board. If item 3 of board is item 4 of board and item 4 of board is item 5 of board and item 3 of board is not 0, set winner to item 3 of board. If item 6 of board is item 7 of board and item 7 of board is item 8 of board and item 6 of board is not 0, set winner to item 6 of board. If item 0 of board is item 3 of board and item 3 of board is item 6 of board and item 0 of board is not 0, set winner to item 0 of board. If item 1 of board is item 4 of board and item 4 of board is item 7 of board and item 1 of board is not 0, set winner to item 1 of board. If item 2 of board is item 5 of board and item 5 of board is item 8 of board and item 2 of board is not 0, set winner to item 2 of board. If item 0 of board is item 4 of board and item 4 of board is item 8 of board and item 0 of board is not 0, set winner to item 0 of board. If item 2 of board is item 4 of board and item 4 of board is item 6 of board and item 2 of board is not 0, set winner to item 2 of board. Add 1 to turn.

If winner is 1, show "A". If winner is 2, show "B". If winner is 0 and turn is 9, show "Draw". If winner is 0 and turn is less than 9, show "Pending".

Open in Playground Browse all 1,000 problems

Expected stdout

A