Last active
November 16, 2024 23:34
-
-
Save guillochon/50e65dfa50688f6bef49454659abe0ce to your computer and use it in GitHub Desktop.
Find maximum possible NYT Spelling Bee score when 5 of the letters are vowels
This file contains hidden or 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
# beewords.txt pulled from https://web.archive.org/web/20220909202900/https://beesquared.ga/words.txt | |
from tqdm import tqdm | |
with open("beewords.txt") as f: | |
words = set(f.read().splitlines()) | |
words = set([_.lower().strip() for _ in words if len(_) >= 4 and "s" not in _.lower()]) | |
fivevowels = [word for word in words if len(set(word).intersection(set("aeiou"))) == 5] | |
# print(fivevowels) | |
# print(set(words).intersection(set(fivevowels))) | |
def bee_score(word, letters): | |
if len(word) == 4: | |
return 1 | |
score = len(word) | |
if set(word) == set(letters): | |
score += 7 | |
return score | |
possible_combos = [] | |
vowels = "aeiou" | |
consonants = "bcdfghjklmnpqrstvwxyz" | |
# all two letter permutations of 2 consonants, excluding the same letter twice and different orderings of the same two letters | |
for c1 in consonants: | |
for c2 in consonants: | |
if c1 != c2 and c1 + c2 not in possible_combos and c2 + c1 not in possible_combos: | |
possible_combos.append(c1 + c2) | |
possible_combos = [vowels + _ for _ in possible_combos] | |
combo_scores = [] | |
for combo in tqdm(possible_combos): | |
for req_ind in range(1, len(combo)): | |
scoring_words = [word for word in words if set(word).issubset(combo) and combo[req_ind] in set(word)] | |
pangrams = [word for word in scoring_words if set(word) == set(combo)] | |
if not len(pangrams): | |
continue | |
word_scores = list(sorted([(word, bee_score(word, combo)) for word in words if set(word).issubset(combo) and combo[req_ind] in set(word)], key=lambda x: x[1], reverse=True)) | |
total_score = sum(_[1] for _ in word_scores) | |
if total_score > 0: | |
combo_scores.append([combo, req_ind, total_score, pangrams]) | |
combo_scores = list(sorted(combo_scores, key=lambda x: x[2])) | |
best = combo_scores[-1] | |
print("\n".join(f'{"".join([__.upper() if i == _[1] else __ for i, __ in enumerate(_[0])])} {_[2]} {"/".join(_[3])}' for _ in combo_scores)) | |
print(", ".join(sorted([word for word in words if set(word).issubset(best[0]) and best[0][best[1]] in set(word)]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment