Home>

I have two txt files, one txt file contains a matrix (puzzle)

vlrtakeon
itredflow
ntuemturn
trgteaylp
arraysryi
gshjshhkg
etoesingg

and the other contains the words to be found from the puzzle

vintage
take
flow
remark
tea
array
toe
sing
turn
red
pig

You need to find the coordinates of unused characters and display them. Words can be searched horizontally, vertically, and along all diagonals. Each letter can be used multiple times. The best I could compose is finding each word, but, probably, there is still a long way to go.

with open ("puzzle.txt") as f:
    puzzle= [list (line.strip ()) for line in f]
with open ("words.txt") as f:
    words= [line.strip () for line in f]
print (words)
puzzle_h= ['' .join (i) for i in puzzle]
puzzle_v= ['' .join (i) for i in [* zip (* puzzle)]]
words= ['' .join (i) for i in words]
print (* puzzle_h, sep= '\ n')
print ('=' * 20)
for word in words:
    for j in puzzle_h:
        if j.find (word)!= -1:
            print (f '{word} \ t in {j}')
    for j in puzzle_v:
        if j.find (word)!= -1:
            print (f '{word} \ t in {j}')

I know that I need to work in two-dimensional arrays, I did just that, but I can't figure out how to connect each letter so that I understand which letter was not used. I wanted to write a function that for each character from the first array returns True if the letter was used, and False if it was not used, but the function counts those letters out of order, but simply checks if there is a letter from the second array in the first array (if letters, you get the same word).

Well, now, can you explain how to write a function so that the strict order of characters is observed