Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
14-liner: cleanest for any sequence length solution in Clear category for Find Sequence by przemyslaw.daniel
def checkio(matrix, sequence_length=4):
from itertools import product
r_size, line = range(len(matrix)), range(sequence_length)
cells = {(i, j) for i, j in product(r_size, r_size)}
for i, j in product(r_size, r_size):
horizontal = {(i, j+k) for k in line} & cells
vertical = {(i+k, j) for k in line} & cells
diagonal_1 = {(i+k, j+k) for k in line} & cells
diagonal_2 = {(i+k, j-k) for k in line} & cells
result = [horizontal] + [vertical] + [diagonal_1] + [diagonal_2]
result = [list(x)*(len(x) == sequence_length) for x in result]
if any(len(set(matrix[x][y] for x, y in r)) == 1 for r in result):
return True
return False
Jan. 1, 2018
Comments: