Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Find Sequence by artakase
from itertools import chain, repeat
import re
def checkio(matrix):
n = len(matrix)
for row in chain(
(zip(range(n), repeat(k)) for k in range(n)),
(zip(repeat(k), range(n)) for k in range(n)),
(zip(range(n), range(k, n)) for k in range(n - 3)),
(zip(range(n), range(k, n)) for k in range(n - 3)),
(zip(range(k, n), range(n)) for k in range(1, n - 3)),
(zip(range(n), reversed(range(k, n))) for k in range(n - 3)),
(zip(range(k, n), reversed(range(n))) for k in range(1, n - 3))):
if re.findall(r'(\d)\1{3}',
''.join(str(matrix[i][j]) for i, j in row)):
return True
else:
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"
Nov. 20, 2015
Comments: