Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Find Sequence by KarolinaK
def checkio(matrix):
n=len(matrix)
l1=l2=0
for i in range(0,n):
for j in range(1,n):
if(matrix[i][j]==matrix[i][j-1]):
l1+=1
else:
l1=0
if(matrix[j][i]==matrix[j-1][i]):
l2+=1
else:
l2=0
print(l1,l2)
if(l1==3 or l2==3):
return True
l1=l2=l3=l4=0
p=n-1
print("---------------------------------")
for i in range(0,n-3):
for j in range(0,p):
if(matrix[i+j][j]==matrix[i+j+1][j+1]):
print(matrix[i+j][j],matrix[i+j+1][j+1])
l1+=1
else:
l1=0
if(matrix[j][i+j]==matrix[j+1][i+j+1]):
print(matrix[j][i+j],matrix[j+1][i+j+1])
l3+=1
else:
l3=0
if(matrix[i+j][n-1-j]==matrix[i+j+1][n-1-j-1]):
l2+=1
else:
l2=0
if(matrix[j][n-1-j-i]==matrix[j+1][n-1-i-j-1]):
l4+=1
else:
l4=0
print(l1,l2)
if(l1==3 or l2==3 or l3==3 or l4==3):
return True
p=p-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"
Oct. 23, 2016