Skip to content

Instantly share code, notes, and snippets.

@brubsby
Created September 11, 2023 02:19
Show Gist options
  • Save brubsby/a9105a393a6aea18ade068d7e1998129 to your computer and use it in GitHub Desktop.
Save brubsby/a9105a393a6aea18ade068d7e1998129 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import marisa_trie
def get_five_letter_words_from_file(filename):
words = []
with open(filename, 'r') as file:
next(file) # Skip the header line
for line in file:
columns = line.split()
if len(columns) < 2 or len(columns[1]) != 5: # Check if there's a word in the line
continue
words.append(columns[1].lower())
return words
months = [
"april",
"march",
"nvmbr",
"dcmbr"
]
words = get_five_letter_words_from_file('frequency-alpha-alldicts.txt')
trie = marisa_trie.Trie(words)
for word_1a in words:
for word_1d in trie.keys(word_1a[0]):
for word_2a in trie.keys(word_1d[1]):
for word_2d in trie.keys(word_1a[1] + word_2a[1]):
for word_3a in months:
if word_3a[0] != word_1d[2] or word_3a[1] != word_2d[2]:
continue
for word_3d in [month for month in months if word_3a not in months]:
if word_3d[0] != word_1a[2] or word_3d[1] != word_2a[2] or word_3d[2] != word_3a[2]:
continue
for word_4a in trie.keys(word_1d[3] + word_2d[3] + word_3d[3]):
for word_4d in trie.keys(word_1a[3] + word_2a[3] + word_3a[3] + word_4a[3]):
for word_5a in trie.keys(word_1d[4] + word_2d[4] + word_3d[4] + word_4d[4]):
for word_5d in trie.keys(word_1a[4] + word_2a[4] + word_3a[4] + word_4a[4] + word_5a[4]):
answer = "\n".join([word_1a, word_2a, word_3a, word_4a, word_5a])
print(answer)
print("-----")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment