Skip to content

Instantly share code, notes, and snippets.

@pochmann
Created August 7, 2022 00:02
Show Gist options
  • Save pochmann/7c0e48f523a2aa1edebbb69145b74407 to your computer and use it in GitHub Desktop.
Save pochmann/7c0e48f523a2aa1edebbb69145b74407 to your computer and use it in GitHub Desktop.
Find all sets of five Wordle words without repeated letters
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)
@pochmann
Copy link
Author

pochmann commented Aug 7, 2022

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:

547117 0.6589927673339844
1020296 5.930372714996338
36183 9.305698871612549
3 9.440155267715454
28 winners 10.034610509872437
BEMIX-CLUNK-GRYPT-VOZHD-WAQFS
BLING-JUMPY-TRECK-VOZHD-WAQFS
BLUNK-CIMEX-GRYPT-VOZHD-WAQFS
BRICK-GLENT-JUMPY-VOZHD-WAQFS
BRUNG-CYLIX-KEMPT-VOZHD-WAQFS
BRUNG-KEMPT-VOZHD-WAQFS-XYLIC
CHUNK-FJORD-GYMPS-VIBEX-WALTZ
CLIPT-JUMBY-KRENG-VOZHD-WAQFS
FJORD-GUCKS-NYMPH-VIBEX-WALTZ
GLENT-JUMBY-PRICK-VOZHD-WAQFS
JUMBY-PLING-TRECK-VOZHD-WAQFS
10.190529823303223

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment