3 ms·
Show HN: Simple Wordle solver in command line in Python
- fzxu22 5y agosee README
- nanis 5y agoCorrection: I thought this was script to solve Wordle puzzles, so I provided a cheat helper below. At first blush, I thought the idea was for the human to feed this script information back from Wordle so it could improve its guesses. Sigh Also, you really need better names for your methods and variables, starting with this bit here: https://github.com/KevinXuxuxu/wordle_machine/blob/64a8534ad72df4bc9ba92de044e4e597b0094b3c/wordle_machine.py#L18 https://github.com/KevinXuxuxu/wordle_machine/blob/64a8534ad... As you think about a better way to name those, you will realize it is possible to do this in a much less convoluted way. Hmmm, I have been using this Perl script: #!/usr/bin/env perl use strict; use warnings; use feature 'say'; my @words = grep # Add conditions below !/^[A-Z]/, grep length == 5, map split, do { local $/; <> }; say for @words Invoke it from the command line with your word list. I've been lazy, so I use `./wg /usr/share/dict/words` which means way more options than a more tailored word list would give which means I am only cheating a little. So, for example, I type "amber" as my first move and I am told "e" is in the wrong spot and none of the other letters match, I update the selection using that information: my @words = grep # Add conditions below !/^...e/ && /e/ && !/[ambr]/ && !/^[A-Z]/, grep length == 5, map split, do { local $/; <> };
- fzxu22 5y agoThanks for the reply! I really appreciate your feedback on this. I wasn't giving much thought about coding style and naming etc. when I worked on this, just wanted to get it running asap. I'll definitely take a better look at your suggestion (I'm not very familiar with perl) and see if I find any time to improve this thing. cheers.
- nanis 5y agoMy cheat script will not help with refactoring your code, but note that with a helper data structure, you do not need multiple passes over the guess to mark each letter in one of three states. Write down the process in human language first, then write the code to do the thing instead of immediately diving into the code and rearranging it until it produces the desired result. These exercises are great at improving your intuition and aptitude for refactoring code in a way that makes it more maintainable, easier to read and reason about.
- TheRealNGenius 5y agoin my opinion, this misses the point of wordle
- fzxu22 5y agoYou ... are not wrong ;)
- TheRealNGenius 5y agostill cool tho :)
- oneoff786 5y agoIs Aeros the entropy maximizing first guess?
- fzxu22 5y agoProbably true according to this post: https://slc.is/#Best%20Wordle%20Strategy%20%E2%80%94%20Explore%20or%20Exploit https://slc.is/#Best%20Wordle%20Strategy%20%E2%80%94%20Explo...
- bfung 5y agoNo need to “entropy maximize”. There’s only ~12k-13k five letter English words in the dictionary. Check /usr/share/dict/words file (if you use Windows, go find a dictionary file elsewhere). The first word should be a word that roughly eliminates half the words, regardless of getting any letters right or wrong. Count the letters in each position and calculate & rank the words that closely eliminates 1/2 the whole list. Use that as a filter and binary search until there’s only 1 word left. Wordle is the same game as mastermind and hangman and wheel of fortune. I’d argue Aeros is not the optimal first word in order to filter and binary search the list of five letter words. Homework to be left to the wordler.
- oneoff786 5y agoYou basically described entropy maximization. But not quite. Eliminating words is just a piece of it, and the goal varies. are you trying to minimize the average number of guesses? Maximize the probability of getting it within N guesses? Etc. Binary search isn’t the right answer here. You should be able to do far better than splitting things in half. The greedy approach to solve this would be fairly simple. Find the next choice of n and letter that maximizes information gain recursively until the space is solved. But a globally optimal approach would be pretty hard. At a minimum each letter has three color states so that’s 5^3 (125) groups of words that will be outputted by your result. The ideal first word, assuming your goal is to minimize average guesses, would try to get these groups as even as possible. The theoretical perfect first word would thus get 96 possibilities (12000/125) left after a single guess but that’s probably not possible due to the grouping of words. However a truly globally optimal setup only needs to guarantee that each outcome state has no more than 125 possibilities remaining, all of which are uniquely identifiable with a follow up word. Damn, this sounds like a fun MIP challenge.
- AnnikaL 5y agoit's much less algorithmically interesting, but you can also just run this in your browser console: JSON.parse(window.localStorage.gameState).solution
- fzxu22 5y agoLOL that's actually very useful as I'm trying to find out how the thing works