Coder Social home page Coder Social logo

wordle_solver's Introduction

Wordle Solver

This is the code for a wordle solver for the 538 Riddler puzzle here

For the goal of maximizing the probability of winning within 3 turns, this code finds the best starting word, which results in 1388/2314 words winning within 3 turns (59.98%): trace.

[Update 1/21: An earlier bug had me ignoring the last word of each list, making trace now the unique best starting word]

Strategy explanation

The strategy is simplest to explain starting backwards:

  • For guess 3, choose the remaining possible answer that comes first alphabetically.
  • For guess 2, choose the word that maximzies the number of different color patterns we can recieve.
  • For guess 1, precompute the best word to guess by brute forcing all possibilities.

The only non-trivial part of this strategy is guess 2. To explain why our strategy makes sense, notice that the probability of winning in guess 3 is: 1/[# remaining answers after guess 2].

To maximize the probability of winning in guess 3, we want the average number of remaining answers after guess 2 to be as low as possible. If we have C different color patterns that can result from our second guess, then the average number of remaining answers after guess 2 will be [# remaining answers after guess 1]/C. So we reach the conclusion that the largest value of C will lead to the highest probability of winning.

Using the strategy

Which word is best for the second guess depends on the feedback from the first guess. The file trace_second_guess.txt gives the list of appropriate second guesses for each possible piece of feedback.

The third guess is up to you!

Running the code

The code is written in the Zig programming language, which can be downloaded here.

Compile with:

zig build-exe wordle.zig -O ReleaseFast
Usage:
wordle first [threads] --
     calculate optimal first word (about 40 minutes with threads=1 )

wordle second [first-guess] --
     print out a table of second guess words to use for each possible
     response to the first guess

What I ran:

./wordle first 4
./wordle second trace 2> trace_second_guess.txt
./wordle second slate 2> slate_second_guess.txt

wordle_solver's People

Contributors

bnprks avatar

Stargazers

Owen Peterson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.