Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Find Sequence by szneqz
def checkio(matrix):
leng = len(matrix)
i = 0
j = 0
if leng < 4:
return False
#horizontal
while i < leng:
j = 0
while j <= (leng - 4):
same = matrix[i][j]
if matrix[i][j + 1] == same and matrix[i][j + 2] == same and matrix[i][j + 3] == same:
print("hor")
return True
j = j + 1
i = i + 1
i = 0
#verical
while i < leng:
j = 0
while j <= (leng - 4):
same = matrix[j][i]
if matrix[j + 1][i] == same and matrix[j + 2][i] == same and matrix[j + 3][i] == same:
print("ver")
return True
j = j + 1
i = i + 1
#diagonal left to right
i = 0
while i <= (leng - 4):
j = 0
while j <= (leng - 4):
same = matrix[i][j]
if matrix[i+1][j+1] == same and matrix[i+2][j+2] == same and matrix[i+3][j+3] == same:
print("ltr")
return True
j = j + 1
i = i + 1
#diagonal right to left
i = 0
while i <= (leng - 4):
j = leng - 1
while j >= 3:
same = matrix[i][j]
if matrix[i+1][j-1] == same and matrix[i+2][j-2] == same and matrix[i+3][j-3] == same:
print("rtl", matrix[i][j], matrix[i+1][j-1], matrix[i+2][j-2], matrix[i+3][j-3])
return True
j = j - 1
i = i + 1
print(" ")
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
checkio([[1,7,6,1,8,5,1],[7,9,1,7,2,8,6],[5,1,4,5,8,8,3],[8,6,3,9,7,6,9],[9,8,9,8,6,8,2],[1,7,2,4,9,3,8],[9,9,8,6,9,2,6]])
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"
Jan. 22, 2018