Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Find Sequence by TovarischZhukov
def vert_hor(data, i, j, val, isVert=True, count=1):
pos = i + 1 if isVert else j + 1
while pos < len(data):
if isVert and data[pos][j] == val: count += 1
elif isVert: break
if not isVert and data[i][pos] == val: count += 1
elif not isVert: break
pos += 1
pos = i - 1 if isVert else j - 1
while pos >= 0:
if isVert and data[pos][j] == val: count += 1
elif isVert: break
if not isVert and data[i][pos] == val: count += 1
elif not isVert: break
pos -= 1
return count >= 4
def diag(data, i, j, val, positive=True, count=1):
posi = i + 1 if positive else i + 1
posj = j + 1 if positive else j - 1
while posi < len(data) and posj >= 0 and posj < len(data):
if data[posi][posj] == val: count += 1
else: break
posi = posi + 1 if positive else posi + 1
posj = posj + 1 if positive else posj - 1
posi = i - 1 if positive else i - 1
posj = j - 1 if positive else j + 1
while posj < len(data) and posj >= 0 and posi >= 0:
if data[posi][posj] == val: count += 1
else: break
posi = posi - 1 if positive else posi - 1
posj = posj - 1 if positive else posj + 1
return count >= 4
def checkio(data):
for i, elem in enumerate(data):
for j, val in enumerate(elem):
if vert_hor(data, i, j, val) or vert_hor(data, i, j, val, False) or diag(data, i, j, val) or diag(data, i, j, val, False):
return True
return False
Dec. 8, 2015