Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
newbie solution in Clear category for Find Sequence by ewa_c
def controlDiagOne(matr, x, y):
a = matr[x][y]
if a == matr[x+1][y+1] and a == matr[x+2][y+2] and a == matr[x+3][y+3]:
return True
return False
def controlDiagTwo(matr, x, y):
a = matr[x][y]
if a == matr[x-1][y+1] and a == matr[x-2][y+2] and a == matr[x-3][y+3]:
return True
return False
def controlHori(matr, x, y):
for m in range(4):
a = matr[x][y+m]
if a == matr[x+1][y+m] and a == matr[x+2][y+m] and a == matr[x+3][y+m]:
return True
return False
def controlVert(matr, x, y):
for m in range(4):
a = matr[x+m][y]
if a == matr[x+m][y+1] and a == matr[x+m][y+2] and a == matr[x+m][y+3]:
return True
return False
def checkio(matrix):
#replace this for solution
print(len(matrix))
for n in range(len(matrix)-3):
for o in range(len(matrix)-3):
if controlHori(matrix, n, o):
return True
if controlVert(matrix, n, o):
return True
if controlDiagOne(matrix, n, o):
return True
if controlDiagTwo(matrix,n+3,o):
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"
Jan. 9, 2017