Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.search solution in Clear category for Find Sequence by gyahun_dash
from itertools import chain, zip_longest
from operator import add
from re import search
def read_longitudinally(strings) -> 'generator of strings':
return (''.join(s).strip() for s in zip_longest(*strings, fillvalue = ' '))
def checkio(matrix: '2d-list of integers') -> bool:
rows = [''.join(map(str, row)) for row in matrix]
columns = read_longitudinally(rows)
# get diagonals
shears = [' ' * length for length in range(len(rows))] # '', ' ', ' ', ...
slashes = read_longitudinally(map(add, shears, rows))
backslashes = read_longitudinally(map(add, reversed(shears), rows))
lines = chain(rows, columns, slashes, backslashes)
return any(search(r'(\d)\1{3,}', line) != None for line in lines)
May 16, 2014