Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Uncategorized category for Find Sequence by old_user
# migrated from python 2.7
def checkio(matr):
l_x = len(matr)
l_y = len(matr[0])
#I try every value in matrix and check it for beginning of the sequence
for x in range(l_x):
for y in range(l_y):
#check horizontal
if (y+4 <= l_y and
all([matr[x][y] == matr[x][y+i] for i in range(4)])):
return True
#check vertical
if (x+4 <= l_x and
all([matr[x][y] == matr[x+i][y] for i in range(4)])):
return True
#check right-down diagonal
if (x+4 <= l_x and y+4 <= l_y and
all([matr[x][y] == matr[x+i][y+i] for i in range(4)])):
return True
#check left-down diagonal
if (x+4 <= l_x and y+1 >= l_y and
all([matr[x][y] == matr[x+i][y-i] for i in range(4)])):
return True
return False
if checkio([[1, 1, 1, 1], [1, 2, 3, 4], [5, 4, 3, 1], [6, 1, 3, 2]]): print("First Done")
if checkio([[1, 4, 7, 5], [1, 1, 3, 4], [5, 4, 1, 1], [6, 1, 3, 1]]): print("Second Done")
if checkio([[1, 5, 3, 2], [1, 2, 3, 4], [1, 4, 3, 1], [1, 1, 3, 2]]): print("Third Done")
if checkio([[1, 5, 4, 2, 3],
[2, 2, 7, 3, 5],
[1, 4, 3, 5, 4],
[1, 3, 3, 2, 5]]): print("Four Done")
April 17, 2011
Comments: