Skip to content

Instantly share code, notes, and snippets.

@matpalm
Created April 17, 2012 02:14
Show Gist options
  • Save matpalm/2402945 to your computer and use it in GitHub Desktop.
Save matpalm/2402945 to your computer and use it in GitHub Desktop.
puzzle.py
import sys
# wget http://www.mieliestronk.com/corncob_lowercase.zip
# unzip corncob_lowercase.zip
# echo -e "i\na" >> corncob_lowercase.txt
q = []
words = set()
for word in map(str.strip, sys.stdin):
if len(word) == 10:
q.append([word])
elif len(word) < 10:
words.add(word)
while q:
next = q.pop()
word = next[0]
if len(word)==1:
print list(reversed(next))
else:
for i in range(0,len(word)):
one_letter_removed = word[:i] + word[i+1:]
if one_letter_removed in words:
q.append([one_letter_removed] + next[:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment