Skip to content
/ wordler Public

A Python Wordle solver, inspired by 3Blue1Brown.

License

Notifications You must be signed in to change notification settings

chitvs/wordler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wordler, a Python Wordle solver

Wordler is a Python program designed to solve the popular word game Wordle. The solver uses strategic guessing and feedback processing to efficiently narrow down the list of possible solutions, aiming to solve the puzzle in the fewest possible guesses.

Features

  • Strategic initial guess: starts with an optimal guess to cover common letters.
  • Feedback processing: filters the list of possible words based on feedback from guesses.
  • Best guess selection: uses letter frequencies to select the next guess that maximizes information gain.
  • Simulation mode: runs the solver on all possible Wordle solutions to evaluate its performance.

Optimization

This program can be further optimized by calculating entropy after each guess. By selecting the guess that maximizes the information gain (reduces uncertainty the most), the solver can improve its efficiency. This approach is inspired by the video "Solving Wordle Using Information Theory" by 3Blue1Brown, which explains the concepts of entropy and information theory in the context of solving Wordle.

Requirements

  • Python
  • JSON file containing a frequency map (data/freq_map.json)
  • Text file containing allowed words (data/allowed_words.txt)

File structure

src/
├── wordle.py          
├── wordle_auto.py             
├── data/
│   ├── allowed_words.txt
│   ├── possible_words.txt    
│   ├── nyt_words.txt          
│   ├── solutions.txt          
│   ├── freq_map.json         
│   └── ...                    

where:

  • src/wordle.py: main program file containing the Wordle solver logic.
  • src/wordle_auto.py: script to run simulations and evaluate performance.
  • src/data/allowed_words.txt: list of all allowed 5-letter words.
  • src/data/possible_words.txt: list of 5-letter words with a higher probability of being the solution.
  • src/data/nyt_words.txt: list of NYT Wordle allowed words.
  • src/data/solutions.txt: list of all possible solutions.
  • src/data/freq_map.json: JSON file with word frequency data used to score guesses.
  • Other data files: additional files can be added to enhance the solver's efficiency by providing more information for guess optimization.

Usage

Running the solver

To run the Wordle solver for a single interactive session:

  1. Clone the repository:

    git clone https://github.com/chitvs/wordler.git
  2. Navigate to the project directory:

    cd wordler
  3. Execute the solver script: run the wordle.py script located in the src directory:

    python src/wordle.py
  4. Interactive session: the program will prompt you to enter feedback for each guess. Feedback should be in the format of g (green), y (yellow), and b (black), where:

    • g indicates that a letter is correct and in the correct position.
    • y indicates that a letter is correct but in the wrong position.
    • b indicates that a letter is not in the solution.

Provide your guesses and feedback as prompted.

Example

Running simulations

To run the solver on all possible Wordle solutions and evaluate its performance:

  1. Clone the repository:

    git clone https://github.com/chitvs/wordler.git
  2. Navigate to the project directory:

    cd wordler
  3. Execute the simulation script: run the wordle_auto.py script located in the src directory:

    python src/wordle_auto.py

    This will simulate solving the puzzle for each word in src/data/allowed_words.txt and print the number of guesses needed for each solution, as well as the average number of guesses and other performance data.

Code overview

Main functions

  • load_word_list(filename): loads a list of 5-letter words from a file.
  • filter_words(input_list, feedback, current_guess): filters words based on feedback for each letter and position.
  • generate_feedback(solution, guess): generates feedback for a guess compared to the solution.
  • find_best_guess(possible, data): finds the best guess based on a frequency map.
  • wordle_solver_auto(solution, allowed_words, data): solves Wordle for a given solution with automatic feedback generation.
  • run_all_solutions_auto(): runs the solver for all possible solutions and prints performance statistics.

License

This project is licensed under the MIT License.

About

A Python Wordle solver, inspired by 3Blue1Brown.

Resources

License

Stars

Watchers

Forks

Languages