Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Find Sequence by PawelMartyniuk
def checkio(matrix):
#replace this for solution
numberofrows = len(matrix)
n = 0
while (numberofrows >= n +4):
possible = len(matrix) - 4
row1=matrix[n]
row2=matrix[n+1]
row3=matrix[n+2]
row4=matrix[n+3]
k = 0
while (k=0):
if (row1[possible] == row1[possible+1]== row1[possible+2] == row1[possible+3]):
return True
if (row2[possible] == row2[possible+1]== row2[possible+2] == row2[possible+3]):
return True
if (row3[possible] == row3[possible+1]== row3[possible+2] == row3[possible+3]):
return True
if (row4[possible] == row4[possible+1]== row4[possible+2] == row4[possible+3]):
return True
if (row1[possible] == row2[possible+1]== row3[possible+2] == row4[possible+3]):
return True
if (row1[-1-possible] == row2[-2-possible]== row3[-3-possible] == row4[-4-possible]):
return True
possible -= 1
n = n + 1
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"
Oct. 29, 2016