Skip to content

Instantly share code, notes, and snippets.

@JustinAzoff
Last active August 6, 2022 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinAzoff/171bb7799e3ca632a33037496fb792e7 to your computer and use it in GitHub Desktop.
Save JustinAzoff/171bb7799e3ca632a33037496fb792e7 to your computer and use it in GitHub Desktop.
Summer of Math Exposition 2
#!/usr/bin/env python3
from collections import defaultdict
import string
import sys
def get_words():
words = [w.strip() for w in open("wordle-nyt-allowed-guesses.txt")]
words += [w.strip() for w in open("wordle-nyt-answers-alphabetical.txt")]
words = set(words)
words = [w for w in words if len(set(w)) == 5]
return words
def show(word_mapping, s):
return '/'.join(word_mapping[''.join(sorted(s))])
def do_solve(word_mapping, all_words, path):
if len(path) == 5:
for w in path:
print(show(word_mapping, w), end=" ")
print()
return
for cur in all_words:
# For the first 2 words, pick something with q or a x,
# then a w or v. we need a least one of these in each word.
# based on Counter(open("wordle-nyt-allowed-guesses.txt").read()).most_common(100)
if len(path) == 0 and 'q' not in cur and 'x' not in cur:
continue
if len(path) == 1 and 'j' not in cur and 'z' not in cur:
continue
if len(path) == 2 and 'w' not in cur and 'v' not in cur:
continue
rest = [w for w in all_words if not (w & cur)]
do_solve(word_mapping, rest, path + [cur])
def solve(words):
word_mapping = defaultdict(list)
for w in words:
word_mapping[''.join(sorted(w))].append(w)
#for w, l in word_mapping.items():
# print(w,l)
all_words = [frozenset(w) for w in word_mapping]
print("total words", len(all_words))
do_solve(word_mapping, all_words, [])
def main():
words = get_words()
solve(words)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment