Created
October 21, 2023 16:33
-
-
Save Samasaur1/72d9d60b9a43fd503d7d37d8b095ff7a to your computer and use it in GitHub Desktop.
Find the most four-letter words with the same offsets between letters
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
alphabet = sorted([*"qwertyuiopasdfghjklzxcvbnm"]) | |
def gen_word(i1, i2, i3, i4): | |
return alphabet[i1] + alphabet[i2] + alphabet[i3] + alphabet[i4] | |
with open("/usr/share/dict/words", "r") as file: | |
word_list = [x[:-1] for x in file.readlines() if len(x) == 5] | |
print(len(word_list)) | |
# print(word_list) | |
best_offset = (0,0,0,0) | |
# conceptually, we hold the outer ring constant and find all permutations in the inner rings | |
# for each one, we do the full 26-letter rotation, generating the words | |
for i in range(26): | |
# print(f"i = {i}") | |
for j in range(26): | |
# print(f" j = {j}") | |
for k in range(26): | |
# print(f" k = {k}") | |
words = [] | |
for outer in range(26): | |
w = gen_word(outer, (i + outer) % 26, (j + outer) % 26, (k + outer) % 26) | |
words.append(w) | |
# print(words) | |
valid_words = [x for x in words if x in word_list] | |
count = len(valid_words) | |
if count > 2: | |
print(valid_words) | |
# print(count) | |
# print(words) | |
# print(valid_words) | |
(_,_,_,prev_count) = best_offset | |
if count > prev_count: | |
best_offset = (i,j,k,count) | |
print(f" updating best match to {i},{j},{k} (words: {valid_words})") | |
print(best_offset) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment