Skip to content

Instantly share code, notes, and snippets.

@elidickinson
Created November 18, 2020 02:35
Show Gist options
  • Save elidickinson/3e3e784aef3bc80e9d714f07a5695b52 to your computer and use it in GitHub Desktop.
Save elidickinson/3e3e784aef3bc80e9d714f07a5695b52 to your computer and use it in GitHub Desktop.
# 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