Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Find Sequence by canassa
from itertools import groupby, chain
def has_sequence(l):
"""
Returns True if there is a sequence of 4 or more matching numbers in the `l` list.
"""
return any(g for _, g in groupby(l) if len(list(g)) >= 4)
def diagonal(matrix):
""" Given a matrix, returns its diagonal """
M = list(matrix)
return [[M[y-x][x] for x in range(len(M)) if 0 <= y-x < len(M)] for y in range(2*len(M) - 1)]
def checkio(matrix):
return any(has_sequence(r) for r in chain(matrix, # Horizontal
zip(*matrix), # Vertical
diagonal(matrix), # Diagonal
diagonal(m[::-1] for m in matrix))) # Diagonal reversed
March 4, 2014
Comments: