Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple, using separate function solution in Clear category for Find Sequence by Sebastian.M
def checkIfSeuqence(matrix, posX, posY, dirX, dirY):
pos = matrix[posX][posY]
for i in range(3):
posX+=dirX
posY+=dirY
if(posX>=len(matrix) or posX<0):
return False
if(posY>=len(matrix) or posY<0):
return False
if(pos!=matrix[posX][posY]):
return False
return True
def checkio(matrix):
for y in range(len(matrix)):
for x in range(len(matrix)):
if(checkIfSeuqence(matrix,x,y,1,0) or checkIfSeuqence(matrix,x,y,0,1) or
checkIfSeuqence(matrix,x,y,-1,-1) or checkIfSeuqence(matrix,x,y,-1,1)):
return True
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. 19, 2016