Skip to content

Instantly share code, notes, and snippets.

@mkosler
Created March 25, 2017 14:14
Show Gist options
  • Save mkosler/343b0a914bbec67d67b36ae648e43884 to your computer and use it in GitHub Desktop.
Save mkosler/343b0a914bbec67d67b36ae648e43884 to your computer and use it in GitHub Desktop.
I got frustrated ;)
#!/usr/bin/python
# Arguments:
# A file consisting of all the letters in a column per line.
# For example, a puzzle looking like:
# A B C
# D E F
# G H I
# J K
# L
#
# Would be written in the file as:
# ADGJ
# BEHKL
# CFI
import sys
import enchant
import itertools
engDict = enchant.Dict('en_US')
charLists = []
charPositions = {}
for line in open(sys.argv[1], 'r'):
charLists.append(list(line.strip()))
for maybeWord in [''.join(x) for x in list(itertools.product(*charLists))]:
if engDict.check(maybeWord):
newChars = []
for i, c in enumerate(list(maybeWord)):
if (i, c) not in charPositions:
newChars.append((i, c))
charPositions[(i, c)] = True
if newChars:
print(maybeWord, newChars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment