I wrote this program where you can input
x amount of words that of length
x that checks if the grid formed is the same words vertically as they are horizontally:
F I L E I C E D L E A D E D D Y
The words can be entered in any order and the letters must stay in the same order. i.e.
F I L E can't be
F E L I
The permutations part of my code is so I can get all permutations of the words to check if they work in a grid
This feels very clunky and I'd like to slim it down. Does anyone have any suggestions?
import sys import itertools numWords = int(raw_input('Enter Number of Words: ')) words =  stuff =  for i in range(numWords): word = raw_input('Enter Word: ') if len(word) != numWords: print('Not Valid Grid') sys.exit() words.append(word) stuff = list(itertools.permutations(words)) for i in range(len(stuff)): count = 0 for j in range(0,4): s = '' for k in range(0,4): if stuff[i][j][k] == stuff[i][k][j]: s += stuff[i][k][j] if s in stuff[i]: count += 1 if count == numWords: for l in stuff[i]: print l sys.exit() print('Not a Valid Grid')