Created
April 17, 2012 02:14
-
-
Save matpalm/2402945 to your computer and use it in GitHub Desktop.
puzzle.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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