Settings

Theme

Building a Wordle solver in Python using Knuth's Mastermind algorithm

kerrigan.dev

4 points by joek1301 4 years ago · 4 comments

Reader

joek1301OP 4 years ago

Hi HN! I'm the author of this blog post.

I was stuck in quarantine with COVID, and I became absolutely obsessed with WORDLE. There were a few great technical articles posted here, and I became inspired to write my own WORDLE solver based on Knuth's algorithm for the codebreaking game Mastermind [1].

It's fun to ride the WORDLE trend; it also happens to be a great application for the minimax decision rule.

This is my first blog post, ever! I'm trying to spend a little more time writing and reflecting (on things technical or not). I would be happy to receive feedback if you have anything to say.

[1]: https://stackoverflow.com/questions/62430071/donald-knuth-al...

  • eesmith 4 years ago

    It was a fun read - thanks! Though I'm not your target as the game doesn't interest me, I do sometimes use minimax.

    • joek1301OP 4 years ago

      Thanks for the positive feedback! Out of curiosity: what do you use minimax for?

      • eesmith 4 years ago

        The easiest example I can think of was at the local Python User's Group.

        A local company develops a platform meant to test job applicants for baseline programming skills. It's based around game play. For example, one was to have bots fighting each other in a 2D grid or some such.

        They wanted us to test out their new game, which was a sort of auction/bidding system. All bots start with the same money, and ... it's been so long I don't remember all the details.

        Anyway, the solution I came was, at the very least, based on ideas from minimax: set up a game tree, figure out the payoff matrix, minimize losses. The game tree was so small I could memoize the entire solution space.

        This turned out to be the winning strategy. Except that since their game tree was so small I also proved it was impossible to tell if the winner used the optimal strategy. Basically, if all other bots bet all or nothing and came first then the last bot would never get a chance to outbid the others. OTOH, if they added more items to bit on then the other bots would go bankrupt, leaving the last bot (with a decent strategy) to win the remaining items.

        I pointed this all out to them, they thanked me, and I haven't heard any followup. :) I'm pretty sure they didn't know any game theory when they set up the problem.

        And to be clear, I think the idea was to figure out if someone could program -- I hope not to select the person whose bot was the best.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection