The playable code-breaker accepts four A–F entries, returns anonymous Exact and Misplaced totals and keeps earlier guesses unchanged in the history. Against AABC, AAAA gives Exact 2 and Misplaced 0; BCAA gives Exact 0 and Misplaced 4. A correct eighth attempt wins because the win check comes before the attempt-limit loss.

Consume exact positions before matching the leftovers
Compare the four corresponding positions. An equal pair contributes one Exact match and consumes both that secret slot and that guess slot.
For secret AABC and guess AAAA, the first two positions are exact. Remove those positions from both sides. Secret leftovers are B, C; guess leftovers are A, A. No leftover symbols match, so the result is Exact 2, Misplaced 0.
Counting every guessed A against the original two secret As would reuse already-consumed symbols. A correct result needs a limit on how many times each remaining symbol can match.
To follow the algorithm, cross out the exact pairs first, then write the remaining letters on each side. Keep this calculation separate from the anonymous totals shown to the player.
Intersect residual counts with a minimum
For each symbol, count its occurrences in the unmatched secret and unmatched guess. Its Misplaced contribution is the smaller count. Sum those contributions across A–F.
| Guess against AABC | Exact | Unmatched secret | Unmatched guess | Misplaced |
|---|---|---|---|---|
| AAAA | 2 | B, C | A, A | 0 |
| ADAA | 1 | A, B, C | D, A, A | 1 |
| BCAA | 0 | A, A, B, C | B, C, A, A | 4 |
| AABC | 4 | Empty | Empty | 0 |
For ADAA, the first A is exact. The residual secret has one A, while the residual guess has two. Only one can be credited; B, C and D add no matches. The result is Exact 1, Misplaced 1.
For BCAA, no position is exact. Both sides contain two As, one B and one C, so all four count as misplaced. For AABC, all four slots are exact and nothing remains to match.
Exact plus Misplaced can never exceed four. An exact symbol cannot also count as misplaced. Compare the four worked guesses with the totals in the page’s history.
Publish totals without inventing a slot mapping
The player-facing response says Exact: 1; Misplaced: 1 for ADAA. It does not mark the second or fourth input as the location of the misplaced A.
Keep Exact and Misplaced as labeled totals. Placing a marker under a specific input would imply a positional clue that the matching counts do not provide.
Use the totals to revise your next guess. Exact 1 and Misplaced 1 tells you that two symbols were credited, but it does not identify which unmatched slot contains the misplaced symbol.
Resolve a correct eighth guess before the limit loss
After a valid attempt, check Exact 4 first. That result wins, including on attempt eight. Only an incorrect eighth valid attempt reaches Lost.
| Guess situation | Result |
|---|---|
| Correct AABC on attempt 1 | Won; 7 attempts unused |
| Correct AABC on attempt 8 | Won; 0 attempts unused |
| Incorrect AAAA on attempt 8 | Lost; 0 attempts unused |
| Invalid incomplete input after 7 valid attempts | Still playing; 1 attempt unused |
Won and Lost both block Check guess until Reset. The eight-attempt limit belongs to this example.
Reset restores the same AABC example, collapses the developer key, clears all choices/errors/history, sets attempts to zero and returns to Playing with eight available attempts. It does not generate a new undisclosed key.
The history keeps earlier guesses unchanged when current inputs are edited.
Enter one complete guess
Type one symbol in each labeled slot and press Check guess, or use a fresh Enter in a slot. Missing or outside-bank input consumes no attempt. A valid nonterminal guess clears the four fields after recording its totals; intentionally entering the same guess again uses another attempt. You can open the Developer key explanation to see AABC. Use that disclosure when studying the matching algorithm; the answer is deliberately inspectable. Feedback totals do not identify specific unmatched slots.
Copy this prompt
Make a four-slot code-breaking game with a fixed example answer AABC and eight valid attempts. Use a clear input row, labeled feedback totals and a history of guesses. The symbol bank is A Triangle, B Square, C Circle, D Diamond, E Star and F Hexagon. Show the letters and names so color is unnecessary.
Provide four labeled single-letter inputs and a Check guess button. Trim and uppercase each entry, then require one A through F letter in every slot. Incomplete or outside-bank input displays a correction request without using an attempt. A fresh Enter press in an input performs the same check.
Count exact positions first. Consume those occurrences from both the answer and guess. For each unmatched symbol, add the smaller of its remaining counts to Misplaced. Against AABC, AAAA gives Exact 2 and Misplaced 0; ADAA gives 1 and 1; BCAA gives 0 and 4; AABC gives 4 and 0. Display anonymous totals without implying which unmatched position earned a match.
Each valid guess adds one unchanged history row and consumes one attempt, even when intentionally repeated. Clear the inputs after a nonterminal guess. Check for four exact matches before enforcing the attempt limit, so a correct eighth guess wins and an incorrect eighth guess loses. Further checks have no effect after either ending.
Include a collapsed Developer key explanation showing AABC and the worked guesses. Reset restores the same answer, clears inputs, feedback and history, and collapses that explanation. Return one responsive HTML file with embedded CSS and JavaScript, large inputs and readable attempt history.
Try the repeated-letter guesses
Enter AAAA, then ADAA, and compare how the unmatched As affect Misplaced. Finish the comparison with BCAA, which earns four misplaced matches and no exact ones. NOS can render the HTML code-breaker for this algorithm walkthrough. Open the developer explanation afterward and trace which occurrences each guess consumed.