Created
November 18, 2020 02:35
-
-
Save elidickinson/3e3e784aef3bc80e9d714f07a5695b52 to your computer and use it in GitHub Desktop.
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
# What 8 letter word can have a letter taken away, and each time still make another word, until only one letter (and one word) are left? | |
words_by_length = [set(), set(), set(), set(), set(), set(), set(), set(), set()] | |
with open('scrabble2019.txt') as f: | |
for w in f: | |
word = w.strip() | |
word_len = len(word) | |
if word_len <= 8: | |
words_by_length[word_len].add(word) | |
answers = set() | |
def find_word(word, history): | |
history.append(word) | |
if len(word) == 8: | |
answers.add(word) | |
history.reverse() | |
print(history) | |
return | |
for next_word in words_by_length[len(word)+1]: | |
if word in next_word: | |
find_word(next_word, history[:]) | |
find_word('A', list()) | |
find_word('I', list()) | |
find_word('O', list()) | |
print(answers,len(answers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment