How do you find the coordinates of those symbols that were not used?
-
I have two txt file, one txt file contains a matrix.
vlrtakeon itredflow ntuemturn trgteaylp arraysryi gshjshhkg etoesingg
and the other contains words that need to be found from the puzzle.
vintage take flow remark tea array toe sing turn red pig
We need to find the coordinates of unused symbols and put them on the screen. Words can be found horizontally, vertically and across all diagons. Each letter may be used several times. The best thing I could do was find every word, but it's probably far away.
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 I have to work in two-blocks, and I've done it in the first place, but I can't figure out how to tie every letter to understand what letter was not used. I wanted to write a function which, for each symbol in the first set, reverts True if the letter was used, and False if it was not used, but the function considers those letters not in order, but simply checks whether there is a letter from the second set in the first set (if the letters are combined).
Well, you can explain how you need to write a function so that the strict characters are followed.
-
When you found your word
if j.find(word) != -1:
the index in the line returned corresponds to the range of indices in the matrix. These cells can be marked in the supplementary matrix.
At the end, the unmarked cells correspond to unused letters