Skip to content

Tic-tac-toe winner

Tic-tac-toe winner

Decide a game of noughts and crosses from the board.

There are eight lines to check: three rows, three columns and two diagonals. board[r][c] is the square in row r and column c, so a column is board[0][c] + board[1][c] + board[2][c]. Collect all eight lines as three-letter strings, then look for "XXX" or "OOO".

Log in or create account

IGCSE, A-Level & AP