-
-
Save brubsby/258107611dae337ef57145097584b1b3 to your computer and use it in GitHub Desktop.
crossword helper
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
#!/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]) | |
return words | |
words = get_five_letter_words_from_file('frequency-alpha-alldicts.txt') | |
blank = [ | |
" n ", | |
" v ", | |
"dcmbr", | |
" b ", | |
" r " | |
] | |
# blank = [ | |
# " d ", | |
# " c ", | |
# "nvmbr", | |
# " b ", | |
# " r " | |
# ] | |
trie = marisa_trie.Trie(words) | |
for word_1a in words: | |
if word_1a[2] != blank[0][2]: | |
continue | |
for word_1d in trie.keys(word_1a[0]): | |
if word_1d[2] != blank[2][0]: | |
continue | |
for word_2a in trie.keys(word_1d[1]): | |
if word_2a[2] != blank[1][2]: | |
continue | |
for word_2d in trie.keys(word_1a[1] + word_2a[1] + blank[2][1]): | |
for word_4a in trie.keys(word_1d[3] + word_2d[3] + blank[3][2]): | |
for word_4d in trie.keys(word_1a[3] + word_2a[3] + blank[2][3] + word_4a[3]): | |
for word_5a in trie.keys(word_1d[4] + word_2d[4] + blank[4][2] + word_4d[4]): | |
for word_5d in trie.keys(word_1a[4] + word_2a[4] + blank[2][4] + word_4a[4] + word_5a[4]): | |
answer = "\n".join([word_1a, word_2a, blank[2], 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