Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Find Sequence by arek.kowalski107
def solution1(matrix, i, j):
try:
if (matrix[i][j] == matrix[i+1][j]) and \
(matrix[i][j] == matrix[i+2][j]) and \
(matrix[i][j] == matrix[i+3][j]):
return True
except IndexError:
return False
def solution2(matrix, i, j):
try:
if (matrix[i][j] == matrix[i][j+1]) and \
(matrix[i][j] == matrix[i][j+2]) and \
(matrix[i][j] == matrix[i][j+3]):
return True
except IndexError:
return False
def solution3(matrix, i, j):
try:
if (matrix[i][j] == matrix[i-1][j-1]) and \
(matrix[i][j] == matrix[i-2][j-2]) and \
(matrix[i][j] == matrix[i-3][j-3]):
if (i-1 < 0)or(i-2 < 0)or(i-3 < 0)or(j-1 < 0)or(j-2 < 0)or(j-3 < 0):
return False
return True
except IndexError:
return False
def solution4(matrix, i, j):
try:
if (matrix[i][j] == matrix[i-1][j+1]) and \
(matrix[i][j] == matrix[i-2][j+2]) and \
(matrix[i][j] == matrix[i-3][j+3]):
if (i-1 < 0)or(i-2 < 0)or(i-3 < 0):
return False
return True
except IndexError:
return False
def checkio(matrix):
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if solution1(matrix, i, j) or solution2(matrix, i, j) or \
solution3(matrix, i, j) or solution4(matrix, i, j):
return True
return False
Dec. 14, 2016