Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex solution in Creative category for Find Sequence by ale1ster
import re
from functools import reduce
def checkio(m):
re_pat = '''(?x)
(?# Match either 4 of the same number with nothing between them)
(?: (?: (?P\d) (?P=h){{{rep}}} )
(?# or 4 instances of the same digit with `len` anything in between)
| (?: (?P\d) (?: .{{{vert}}} (?P=v) ){{{rep}}} )
(?# one of the same on the left-to-right diagonal)
| (?: (?P\d) (?: .{{{diag1}}} (?P=d) ){{{rep}}} )
(?# and the other diagonal)
| (?: (?P\d) (?: .{{{diag2}}} (?P=D) ){{{rep}}} )
(?# Note: Instances of the same digit with wrap-around on the table
are not recognized. Also, in the calculations, the delimiter is
taken in consideration)
)'''.format(rep=3, vert=len(m), diag1=len(m)+1, diag2=len(m)-1)
matrix = reduce(lambda acc,row: acc + ';' + row,
[reduce(lambda acc,el: acc + str(el), row, '') for row in m])
return bool(re.findall(re_pat, matrix))
May 24, 2014
Comments: