Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
naïve solution solution in Clear category for Find Sequence by dudas
from typing import List
def check_vertical(M, rr, cc, r_size, c_size):
jj = cc
n = 1
for ii in range(rr + 1, r_size):
if not M[rr][jj] == M[ii][jj]:
return False
else:
n = n + 1
if n == 4:
return True
rr = ii
return False
def check_horizontal(M, rr, cc, r_size, c_size):
ii = rr
n = 1
for jj in range(cc + 1, c_size):
if not M[ii][cc] == M[ii][jj]:
return False
else:
n = n + 1
if n == 4:
return True
cc = jj
return False
def check_SE(M, rr, cc, r_size, c_size):
n = 1
ccc=cc
rrr=rr
c_range = c_size-cc
r_range = r_size-rr
if r_range bool:
# replace this for solution
r_size = len(matrix)
c_size = r_size
tf = False
for ii in range(len(matrix)):
for jj in range(len(matrix)-1):
print(ii,jj) #print(matrix[ii][jj])
tf = tf or check_vertical(matrix, ii, jj, r_size, c_size)
tf = tf or check_horizontal(matrix, ii, jj, r_size, c_size)
tf = tf or check_SE(matrix, ii, jj, r_size, c_size)
tf = tf or check_NE(matrix, ii, jj, r_size, c_size)
if tf:
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
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!')
Nov. 5, 2021