Created
August 7, 2022 00:02
-
-
Save pochmann/7c0e48f523a2aa1edebbb69145b74407 to your computer and use it in GitHub Desktop.
Find all sets of five Wordle words without repeated 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
import glob | |
import numpy as np | |
from itertools import combinations | |
from time import time | |
t0 = time() | |
words = [] | |
for file in glob.glob('wordle*'): | |
with open(file) as f: | |
for word in f.read().split(): | |
if len(set(word)) == 5: | |
mask = sum(2**(ord(c)-97) for c in word) | |
words.append((word, mask)) | |
maskss = [np.array(list({m for _, m in words}), np.int32)] | |
for _ in range(4): | |
maskss.append(np.unique(np.hstack([ | |
maskss[-1][maskss[-1] & m == 0] | m | |
for m in maskss[0] | |
]))) | |
print(len(maskss[-1]), time()-t0) | |
winners = [] | |
for (word, m) in words: | |
for M in maskss[4]: | |
if m & M == m and M - m in maskss[3]: | |
winners.append(word) | |
break | |
print(len(winners), 'winners', time()-t0) | |
for c in combinations(sorted(winners), 5): | |
if len(set(''.join(c))) == 25: | |
print('-'.join(c).upper()) | |
print(time() - t0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use 26-bit ints to represent alphabet subsets that can be built with the Wordle words. I start with the 5-sets from the Wordle words, then compute 10-sets, 15-sets, 20-sets and 25-sets. Then I use that data to find the words that are part of a 25-set. There are only 28 such winner words, and 28C5 is small enough to recreate the actual sets of words by brute force, so I do that. To run this, add the two Wordle list files Matt links to in the video description.
Example output:
Before the 11 solution sets, you see some statistics, like there are 547117 different 10-sets of letters that can be created using two Wordle words. The floating point numbers are the time in seconds from the start of the program. This is from a run on replit.com, couldn't run this on a better computer yet (but I do have a paid account there, so it's not that slow).