Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
matrix solution in Clear category for The Hidden Word by Olpag
def checkio(text, word):
array = text.replace(' ', '').lower().split('\n')
longest = len(max(array, key=len))
matrix = [string + '0' * (longest - len(string)) for string in array]
coords = lambda n, N: ((n - 1) % N + 1, (n - 1) // N + 1)
found, transposed = False, False
while not found:
new_text = ''.join(matrix)
if new_text.find(word) != -1:
x1, y1 = coords(new_text.find(word) + 1, longest)
x2, y2 = x1 + len(word) - 1 , y1
if transposed:
x1, y1 = y1, x1
x2, y2 = y2, x2
found = True
else:
matrix = [''.join(list(i)) for i in zip(*matrix)]
longest = len(matrix[0])
transposed = True
return [y1, x1, y2, x2]
March 24, 2019
Comments: