Created
February 16, 2022 15:47
-
-
Save Lonenso/cf04c11006b69b68612fb8162ddeef9f to your computer and use it in GitHub Desktop.
stupid_wordle_solver
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
import re | |
import sys | |
import signal | |
# TODO: How to increase the possibility for turning yellow to green? | |
def stupid_wordle_solver(wordlist, exclude, include, pattern="_____", limit=5): | |
assert(len(exclude) != 0) | |
exclude_pattern = pattern.replace('_', f"[^{exclude}") | |
candidates = [] | |
r_exclude = re.compile(exclude_pattern) | |
def include_matched(include, word): | |
for c in [*include]: | |
if c not in w: | |
return False | |
return True | |
for w in wordlist: | |
if re.match(r_exclude, w): | |
if include_matched(include, w): | |
candidates.append(w) | |
sort_candidates = sorted(candidates, key=lambda x: len(set(x)), reverse=True) | |
print(sort_candidates[:10]) | |
def handler(signum, frame): | |
sys.exit(1) | |
def valid_re(s): | |
try: | |
re.compile(s) | |
is_valid = True | |
except re.error: | |
is_valid = False | |
return is_valid | |
def main(): | |
signal.signal(signal.SIGINT, handler) | |
wordlist_file = "words_alpha.txt" | |
limit = 5 | |
wordlist = [] | |
with open(wordlist_file, 'r') as f: | |
for w in f: | |
w = w.strip() | |
if len(w) == limit: | |
wordlist.append(w) | |
def suffix(i): | |
d = { | |
1: "st", | |
2: "nd", | |
3: "rd", | |
} | |
if i in d: | |
return d[i] | |
else: | |
return "th" | |
print("""########## | |
letter pattern: | |
the 1st letter pattern (leave empty if no any clues | |
> ee <--- this means the 1th is not 'e' | |
> eng <--- this means the 1th is not 'eng' | |
> e <--- this means the 1th is 'e' | |
##########""") | |
exclude_chars = "" | |
include_chars = "" | |
while 1: | |
pattern = "" | |
for i in range(1, limit + 1): | |
i_letter = input(f"the {i}{suffix(i)} letter pattern (leave empty if no any clues): \n") | |
if len(i_letter) == 1: | |
pattern += i_letter | |
elif i_letter.startswith('?') and valid_re(i_letter[1:]): | |
print("[DEBUG] detect regex...") | |
pattern = i_letter[1:] | |
break | |
elif len(i_letter) > 1: | |
pattern += f"_{i_letter}]" | |
else: | |
pattern += "_]" | |
print(f"[DEBUG] pattern: {pattern}") | |
exclude_chars += input("any new exclude chars?\n") | |
print(f"[DEBUG] exclude_chars: {exclude_chars}") | |
include_chars += input("any new include chars?\n") | |
print(f"[DEBUG] include_chars: {include_chars}") | |
stupid_wordle_solver(wordlist, pattern=pattern, exclude=exclude_chars, include=include_chars, limit=limit) | |
if __name__ == "__main__": | |
main() |
use entropy to solve this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
character frequency.