Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Maybe so solution in Clear category for Find Sequence by fed.kz
DIRS = ((0, 0), (1, 1), (2, 2), (3, 3))
def generate_diags(matrix):
SIZE = len(matrix)
for x in range(SIZE - 3):
for y in range(SIZE - 3):
yield (matrix[x+i][y+j] for i, j in DIRS)
yield (matrix[x+i][SIZE-y-j-1] for i, j in DIRS)
def find4(sequence):
if len(sequence) < 4: return False
if len(set(sequence[:4])) == 1: return True
return find4(sequence[1:])
def checkio(matrix):
for row in matrix:
if find4(row): return True
for col in zip(*matrix):
if find4(col): return True
for diag in generate_diags(matrix):
if find4(list(diag)): return True
return False
Nov. 6, 2018