Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Find Sequence by krzysztof.gonda
def checkio(matrix):
for x in matrix:
count = 1
last = ''
for y in x:
if(last == ''):
last = y
else:
if(y==last):
count+=1
else:
count = 1
last = y
if(count==4):
return True
for x in range(0,len(matrix)):
count = 1
last = ''
for y in range(0,len(matrix)):
if(last == ''):
last = matrix[y][x]
else:
if(matrix[y][x]==last):
count +=1
else:
count = 1
last = matrix[y][x]
if(count==4):
return True
for x in range(3,len(matrix)):
count = 1
last = ''
i = x
for y in range(0,x+1):
if(last == ''):
last = matrix[y][i]
else:
if(matrix[y][i]==last):
count +=1
else:
count = 1
last = matrix[y][i]
if(count==4):
return True
i -=1
for x in range(1,len(matrix)-3):
count = 1
last = ''
y = len(matrix)-1
i = x
while(i<(len(matrix))):
if(last == ''):
last = matrix[y][i]
else:
if(matrix[y][i]==last):
count +=1
else:
count = 1
last = matrix[y][i]
if(count==4):
return True
i +=1
y-=1
for x in range(0,len(matrix)-3):
count = 1
last = ''
i = 0
for y in range(x,len(matrix)):
if(last == ''):
last = matrix[i][y]
else:
if(matrix[i][y]==last):
count +=1
else:
count = 1
last = matrix[i][y]
if(count==4):
return True
i +=1
for x in range(1,len(matrix)-3):
count = 1
last = ''
y = len(matrix)-1
i = x
while(i=0):
if(last == ''):
last = matrix[y][i]
else:
if(matrix[y][i]==last):
count +=1
else:
count = 1
last = matrix[y][i]
if(count==4):
return True
i-=1
y-=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, 2, 1, 2, 1]
]) == True, "Diagonal"
assert checkio([
[1,2,4,6,3],
[2,5,2,6,3],
[8,7,5,9,5],
[2,1,1,4,3],
[4,2,7,5,1]]) == False, 'Nop'
Nov. 21, 2017