As suggested in your commentcomments, the task can be done directly without having to modify values to ints or change the structure of the input.
Input: A tuple A
of n
rows and m
columns.
Output: Whether there is matching $4$ "O"'s or 4 "X"'s on a diagonal, horizontal, or vertical line.
Procedure:
# horizontal lines
For i in range(n):
For j in range(m-3):
Find if A[i][j], A[i][j+1], A[i][j+2], A[i][j+3] are 4 "0"s or 4 "X"s. Return accordingly if yes.
# vertical lines
For j in range(m):
For i in range(n-3):
Find if A[i][j], A[i+1][j], A[i+2][j], A[i+3][j] are 4 "0"s or 4 "X"s. Return accordingly if yes.
# diagonal lines
For i in range(n-3):
For j in range(m-3):
Find if A[i][j], A[i+1][j+1], A[i+2][j+2], A[i+3][j+3] are 4 "0"s or 4 "X"s. Return accordingly if yes.
# other diagonal lines
For i in range(3, n):
For j in range(m-3):
Find if A[i][j], A[i-1][j+1], A[i-2][j+2], A[i-3][j+3] are 4 "0"s or 4 "X"s. Return accordingly if yes.
Return False, since $4$no $4$ "O"'s ornor 4 "X"'s has been found.
ThereOne common difficulty is not a lot of wisdom here. Just make sure ofhow we can figure out the ranges of the possible indices of the staringstarting "O" or "X".
The basic technique is, for example, if A[i-3][j+3]
will be used, then it means "0 <= i-3 < n" and "0 <= j+3 < m", which means "3 <= i < n+3" and "-3 <= j < m -3". Together with "0 <= i < n" and "0 <= j < m", we have "3 <= i < n" and "0 <= j < m-3". That is why you seehow we can write "i in range(3, n)" and "j in range(m-3)" in the case of "other diagonal lines".