Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
A lot of cycles solution in Clear category for Find Sequence by ermichin158
def checkio(matrix):
width = len(matrix)
i = j = 0
hC = vC = drC = dlC = 0
lH = lV = lDR = lDL = matrix[0][0]
while i < width:
j = 0
while j < width:
if matrix[i][j] == lH:
hC += 1
if hC > 3:
return True
else:
hC = 1
lH = matrix[i][j]
if matrix[j][i] == lV:
vC += 1
if vC > 3:
return True
else:
vC = 1
lV = matrix[j][i]
j += 1
i += 1
w = width - 3
i = j = 0
while j < w and i < w:
k = 0
allTrue = True
last = matrix[j][i]
while k < 4:
if matrix[j + k][i + k] != last:
allTrue = False
break
k += 1
if allTrue:
return True
last = matrix[j][i + 3]
k = 0
allTrue = True
while k < 4:
if matrix[j + k][i + 3 - k] != last:
allTrue = False
break
k += 1
if allTrue:
return True
j += 1
if j > w - 1:
j = 0
i += 1
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio([
[1, 2, 1, 1],
[1, 1, 4, 1],
[1, 3, 1, 6],
[1, 7, 2, 5]
]) == True, "Vertical"
assert checkio([
[7, 1, 4, 1],
[1, 2, 5, 2],
[3, 4, 1, 3],
[1, 1, 8, 1]
]) == False, "Nothing here"
assert checkio([
[2, 1, 1, 6, 1],
[1, 3, 2, 1, 1],
[4, 1, 1, 3, 1],
[5, 5, 5, 5, 5],
[1, 1, 3, 1, 1]
]) == True, "Long Horizontal"
assert checkio([
[7, 1, 1, 8, 1, 1],
[1, 1, 7, 3, 1, 5],
[2, 3, 1, 2, 5, 1],
[1, 1, 1, 5, 1, 4],
[4, 6, 5, 1, 3, 1],
[1, 1, 9, 1, 2, 1]
]) == True, "Diagonal"
Nov. 1, 2015