Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Find Sequence by kim.yangjin
def checkio(matrix):
def h_check(matrix):
for i in range(0, len(matrix)):
for j in range(0,len(matrix)):
try:
if matrix[i][j] == matrix[i][j+1] == matrix[i][j+2] == matrix[i][j+3]:
return True
else: continue
except: continue
return False
def v_check(matrix):
for i in range(0, len(matrix)):
for j in range(0,len(matrix)):
try:
if matrix[i][j] == matrix[i+1][j] == matrix[i+2][j] == matrix[i+3][j]:
return True
else: continue
except: continue
return False
def dr_check(matrix):
for i in range(0, len(matrix)):
for j in range(0,len(matrix)):
try:
if matrix[i][j] == matrix[i+1][j+1] == matrix[i+2][j+2] == matrix[i+3][j+3]:
return True
else: continue
except: pass
return False
def dl_check(matrix):
for i in range(0, len(matrix)):
for j in range(3,len(matrix)):
try:
if matrix[i][j] == matrix[i+1][j-1] == matrix[i+2][j-2] == matrix[i+3][j-3]:
return True
else: continue
except: pass
return False
return any([h_check(matrix),v_check(matrix),dr_check(matrix),dl_check(matrix)])
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
assert checkio([
[7, 1, 4, 1],
[1, 2, 5, 2],
[3, 4, 1, 3],
[1, 1, 8, 1]
]) == False
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
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
print('All Done! Time to check!')
Aug. 14, 2020
Comments: