Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Find Sequence by checinski.szymon
def checkio(matrix):
#pionowo
x = 0
y = 1
i = 1
while x < len(matrix[0]):
i = 1
y = 1
while y < len(matrix):
if matrix[y-1][x] == matrix[y][x]:
i += 1
else:
i = 1
if i == 4:
return True
y += 1
x += 1
#poziomo
y = 0
x = 1
while y < len(matrix):
i = 1
x = 1
while x < len(matrix[0]):
if matrix[y][x-1] == matrix[y][x]:
i += 1
else:
i = 1
if i == 4:
return True
x += 1
y += 1
#ukos w prawo
x = 0
i = 1
startY = len(matrix) - 4
while startY > 0:
y = startY
x = 0
i = 1
while y < len(matrix) - 1:
#print(matrix[y][x])
if matrix[y][x] == matrix[y+1][x+1]:
i += 1
else:
i = 1
if i == 4:
return True
y += 1
x += 1
startY -= 1
startX = 0
while startX < len(matrix[0]) - 3:
x = startX
y = 0
i = 1
while x < len(matrix[0]) - 1:
if matrix[y][x] == matrix[y+1][x+1]:
i += 1
else:
i = 1
if i == 4:
return True
y += 1
x += 1
startX += 1
#ukos w lewo
x = 3
y = 0
startX = 3
while startX < len(matrix[0]) - 1:
x = startX
y = 0
i = 1
while x > 0:
#print(str(y) + " " + str(x) + " " + str(matrix[y][x]))
if matrix[y][x] == matrix[y+1][x-1]:
i += 1
else:
i = 1
if i == 4:
return True
y += 1
x -= 1
startX += 1
startY = 0
x = 0
while startY < len(matrix) - 3:
y = startY
x = len(matrix[0]) - 1
i = 1
while x > 0 and y < len(matrix) - 1:
print (str(y) + " " + str(x))
if matrix[y][x] == matrix[y+1][x-1]:
i += 1
else:
i = 1
if i == 4:
return True
y += 1
x -= 1
startY += 1
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
#assert checkio([[1,2,3,4,5,6],[1,2,2,4,5,6],[1,3,4,5,5,6],[4,5,6,1,2,3],[1,4,2,3,1,6],[1,2,3,4,5,6]]) == True, "mine"
print(checkio([[1,5,4,4],[2,2,4,1],[1,4,3,5],[4,3,3,2]]))
#checkio([[2,6,2,2,7,6,5],[3,4,8,7,7,3,6],[6,7,3,1,2,4,1],[2,5,7,6,3,2,2],[3,4,3,2,7,5,6],[8,4,6,5,2,9,7],[5,8,3,1,3,7,8]])
'''
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. 6, 2016