Primel Entropy-Based Solver

An intelligent solver for Primel using information theory and entropy calculations

Python JavaScript Information Theory Web Development

Interactive Demo

Watch the solver in action or try it yourself with your own Primel game state.

Primel Game Board

Click "New Game" to start the demo

Solver Analysis

Start a game to see optimal guesses.

Game Statistics

Remaining Primes: 0
Guesses Made: 0
Target Prime: Hidden

Current Game State

Try it yourself with the actual Primel game!

Add a Guess

Optimal Next Guesses

Enter your game state and click "Get Optimal Guesses" to see recommendations.

Game Statistics

Remaining Primes: 0
Guesses Made: 0

Technical Implementation

JavaScript Web Implementation

To create an accessible web demo, the core Python algorithms were ported to JavaScript, enabling real-time entropy calculations directly in the browser without requiring a backend server.

This implementation features interactive gameplay, smooth animations, and responsive design while maintaining the mathematical accuracy of the original Python solver.

Information Theory Foundation

This solver is based on the information theory approach to Wordle optimization, as explained in 3Blue1Brown's excellent video on the mathematics behind optimal Wordle strategies.

The core idea is to maximize information gain with each guess by calculating the entropy of each possible guess across all remaining valid answers.

Entropy Calculation

For each potential guess, we calculate how it would partition the remaining possible answers based on the feedback patterns it could generate. The entropy formula used is:

H = Σ p(pattern) × log₂(1/p(pattern))

Where p(pattern) is the probability of each possible feedback pattern occurring.

Prime Number Adaptation

Unlike traditional Wordle, Primel uses 5-digit prime numbers as valid answers. This creates a unique constraint set of 8,363 possible answers.

The solver maintains a dynamic list of remaining valid primes and updates it after each guess based on the feedback received.

Implementation Details

The original solver was written in Python for proof of concept, and JavaScript for web deployment. Key components include:

  • Entropy calculation engine
  • Prime list filtering algorithm
  • Feedback pattern generation
  • Interactive web interface
  • Real-time optimal guess ranking

Core Algorithm (JavaScript Implementation)

calculateEntropyForGuess(guess, availablePrimes) {
    if (availablePrimes.length <= 1) return 0;

    // Group primes by their feedback patterns
    const patternGroups = {};

    for (const prime of availablePrimes) {
        const feedback = this.calculateFeedback(guess, prime);
        const patternKey = feedback.join('');

        if (!patternGroups[patternKey]) {
            patternGroups[patternKey] = 0;
        }
        patternGroups[patternKey]++;
    }

    // Calculate entropy using information theory
    let entropy = 0;
    const total = availablePrimes.length;

    for (const count of Object.values(patternGroups)) {
        if (count > 0) {
            const probability = count / total;
            entropy += probability * Math.log2(total / count);
        }
    }

    return entropy;
}

calculateFeedback(guess, target) {
    const guessStr = guess.toString().padStart(5, '0');
    const targetStr = target.toString().padStart(5, '0');
    const feedback = [0, 0, 0, 0, 0];

    // Check for correct positions (green = 2)
    for (let i = 0; i < 5; i++) {
        if (guessStr[i] === targetStr[i]) {
            feedback[i] = 2;
        }
    }

    // Check for correct digits in wrong positions (yellow = 1)
    for (let i = 0; i < 5; i++) {
        if (feedback[i] === 0) { // Not already green
            for (let j = 0; j < 5; j++) {
                if (i !== j && feedback[j] !== 2 && 
                    guessStr[i] === targetStr[j]) {
                    feedback[i] = 1;
                    break;
                }
            }
        }
    }

    return feedback; // [0=gray, 1=yellow, 2=green]
}