Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
29-liner: disjunction of cases solution in Clear category for Find Sequence by Stensen
def rows(grid):
for seq in grid:
for i in range(len(seq)-3):
if len(set(seq[i:i+4])) == 1:
return True; break
return False
def cols(grid):
for seq in zip(*grid):
for i in range(len(seq)-3):
if len(set(seq[i:i+4])) == 1:
return True; break
return False
def backward_diagonals(grid):
fill = [None] * (len(grid) - 1)
grid = [fill[i:] + row + fill[:i] for i, row in enumerate(grid)]
for seq in [[d for d in row if d] for row in zip(*grid)]:
for i in range(len(seq)-3):
if len(set(seq[i:i+4])) == 1:
return True; break
return False
def forward_diagonals(grid):
fill = [None] * (len(grid) - 1)
grid = [fill[:i] + row + fill[i:] for i, row in enumerate(grid)]
for seq in [[d for d in row if d] for row in zip(*grid)]:
for i in range(len(seq)-3):
if len(set(seq[i:i+4])) == 1:
return True; break
return False
checkio = lambda M: rows(M) or cols(M) or backward_diagonals(M) or forward_diagonals(M)
Oct. 23, 2020