Skip to content

This repository contains a Wordle solver implemented in R that utilizes Bayesian statistics to efficiently guess the correct word in the popular word puzzle game, Wordle. By leveraging the principles of Bayesian updating, this solver iteratively refines its guesses based on feedback from previous attempts.

Notifications You must be signed in to change notification settings

MaxMLang/bayesian-wordle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bayesian Wordle Solver

A Wordle solver that uses Bayesian statistics to guess the correct word. This project demonstrates how probability theory can be applied to solve everyday puzzles.

What it does

The solver starts with a list of all possible 5-letter words and uses letter frequency analysis to create initial probabilities. After each guess, it updates these probabilities based on the feedback received (correct letters in right/wrong positions). The goal is to find the word in as few guesses as possible.

How it works

  1. Letter Frequency Analysis: Calculates how often each letter appears in the word list
  2. Initial Scoring: Words with more common letters get higher initial probabilities
  3. Bayesian Updates: After each guess, eliminates words that don't match the feedback
  4. Guess Selection: Picks the word with highest remaining probability

Features

  • Letter frequency analysis for initial word scoring
  • Proper Bayesian probability updating
  • Interactive mode where you provide feedback
  • Automatic mode that solves random words
  • Performance testing on multiple words
  • Verbose logging to see the solver's thought process

How to use

  1. Make sure you have R installed
  2. Put the word list file in the same directory
  3. Run the script and choose your mode:
    • Automatic: Solver picks a random word and solves it
    • Interactive: You provide feedback for each guess

Files

  • bayesian_wordle.R: Main solver script
  • valid-wordle-words.txt: List of valid 5-letter words
  • performance_test.R: Script to test solver performance
  • README.md: This file

Performance

The solver typically finds words in 3-6 guesses, with an average of about 4.5 guesses for successful solves. In testing on 50 random words, it had a 74% success rate.

Some words are easier than others - the solver found "elain" in just 2 guesses, while some words took all 6 guesses.

Technical details

The solver uses entropy calculations to measure how much information each guess provides. Early guesses focus on words with common letters, while later guesses use more sophisticated selection when fewer words remain.

The Bayesian update is straightforward: if a word would produce different feedback than what we received, its probability becomes zero. Otherwise, it keeps its relative probability.

Notes

This is for educational purposes to demonstrate Bayesian statistics. It's not meant to cheat at the actual Wordle game.

The solver works best when it has a good word list. The current list has about 14,855 words, which covers most valid Wordle words.

Future improvements

Could add:

  • Better word selection algorithms
  • Machine learning approaches
  • Support for different word lengths
  • Web interface

Running the tests

To see how well the solver performs, run:

Rscript performance_test.R

This will test 50 random words and show statistics about success rate and average guesses.

About

This repository contains a Wordle solver implemented in R that utilizes Bayesian statistics to efficiently guess the correct word in the popular word puzzle game, Wordle. By leveraging the principles of Bayesian updating, this solver iteratively refines its guesses based on feedback from previous attempts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages