Keep the ten-guess practice program. There are no numbered-line changes here. We will use its visible code 1122 to follow a deduction whose answer we can check.
Complete source at this checkpoint
10 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
200 DIM c(4): LET c(1)=1: LET c(2)=1: LET c(3)=2: LET c(4)=2
220 LET t=1: LET g$="": GO SUB 1000
230 GO SUB 9000
240 GO SUB 2000
250 LET k$=INKEY$: IF k$="" THEN GO TO 250
260 IF k$="q" OR k$="Q" THEN GO TO 8000
270 IF k$="r" OR k$="R" THEN GO TO 200
280 IF k$=CHR$ 13 THEN GO TO 400
290 IF k$="d" OR k$="D" OR k$=CHR$ 12 THEN GO TO 350
300 IF k$<"1" OR k$>"6" THEN GO TO 230
310 IF LEN g$=4 THEN GO TO 230
320 LET g$=g$+k$: GO TO 230
350 IF LEN g$>0 THEN LET g$=g$( TO LEN g$-1)
360 GO TO 230
400 IF LEN g$<>4 THEN PRINT AT 18,2; INK 6;"Enter four digits first. ": GO TO 230
410 GO SUB 3000
420 GO SUB 4000
440 IF t=10 THEN GO TO 5100
450 LET t=t+1: LET g$=""
460 PRINT AT 18,2;" "
470 GO TO 230
1000 CLS
1010 PRINT AT 0,1; INK 5;"LOCKSMITH";AT 0,21; INK 7;"10 TRIES"
1020 PRINT AT 2,1; INK 7;"Practice code: 1122"
1030 PRINT AT 4,1; INK 5;"TRY";AT 4,7;"CODE";AT 4,19;"EXACT";AT 4,26;"OTHER"
1040 FOR j=5 TO 14: PRINT AT j,1; INK 1;"-";AT j,7;". . . .";AT j,21;".";AT j,28;".": NEXT j
1050 PRINT AT 16,1; INK 5;"------------------------------"
1060 PRINT AT 20,1; INK 7;"1-6: digits D: erase"
1070 PRINT AT 21,1;"ENTER: check R: clear Q: quit"
1080 RETURN
2000 PRINT AT 17,1; INK 5;"TRY ";t;" ";AT 17,7; INK 7;"_ _ _ _"
2010 FOR i=1 TO LEN g$: PRINT AT 17,5 +2 *i; PAPER 1; INK 7;g$(i): NEXT i
2020 RETURN
3000 DIM g(4): LET bulls=0: LET total=0
3010 FOR i=1 TO 4: LET g(i)=VAL g$(i): IF g(i)=c(i) THEN LET bulls=bulls+1
3020 NEXT i
3030 FOR d=1 TO 6
3040 LET cc=0: LET gc=0
3050 FOR i=1 TO 4
3060 IF c(i)=d THEN LET cc=cc+1
3070 IF g(i)=d THEN LET gc=gc+1
3080 NEXT i
3090 IF cc<=gc THEN LET total=total+cc
3100 IF gc<cc THEN LET total=total+gc
3110 NEXT d
3120 LET cows=total-bulls: RETURN
4000 PRINT AT 4 +t,1; INK 7;t
4010 FOR i=1 TO 4: PRINT AT 4 +t,5 +2 *i; PAPER 1; INK 7;g$(i): NEXT i
4020 PRINT AT 4 +t,21; INK 4;bulls;AT 4 +t,28; INK 6;cows
4030 RETURN
5100 PRINT AT 17,1; INK 6;"Ten practice guesses recorded. "
5200 PRINT AT 18,1;" ";AT 18,1; INK 7;"The code: ";
5210 FOR i=1 TO 4: PRINT c(i);: NEXT i
5220 PRINT AT 20,1;"R: clear board Q: quit "
5230 PRINT AT 21,1;" "
5240 GO SUB 9000
5250 LET k$=INKEY$: IF k$="" THEN GO TO 5250
5260 IF k$="r" OR k$="R" THEN GO TO 200
5270 IF k$="q" OR k$="Q" THEN GO TO 8000
5280 GO TO 5250
8000 PAPER 0: INK 7: BRIGHT 0: PRINT AT 21,1;"LOCKSMITH finished. ": STOP
9000 IF INKEY$<>"" THEN GO TO 9000
9010 RETURNPress R to clear the board. Submit 1111, then 2222, then 2211. Each new row should agree with this trace:
| Guess | EXACT | OTHER |
|---|---|---|
| 1111 | 2 | 0 |
| 2222 | 2 | 0 |
| 2211 | 0 | 4 |

Find the contents first
With 1111, every possible place for a 1 has been tried. Two matches therefore tell us the code contains exactly two ones. The clue does not identify their positions: any two of the four places could hold them.
The 2222 result tells us there are exactly two twos. Together, these clues fill all four places. No 3, 4, 5 or 6 remains possible. We have reduced the question to arranging two ones and two twos.
The six distinct arrangements are 1122, 1212, 1221, 2112, 2121 and 2211. Repeated digits are why there are only six: swapping the two ones does not make a different code.
Ask where they can go
The third guess, 2211, receives 0 EXACT and 4 OTHER. We already know all four digits belong. The new information is that none occupies its correct position.
Which of the six arrangements survives the third clue, and why?
Show the explanation
1122 survives. The first two positions cannot hold 2 because 2211 earned zero exact matches. They must therefore hold the two ones. The last two positions must hold the two twos. Every other arrangement would share at least one position with 2211.
The positions follow from the combined clues. A single OTHER count does not label individual digits, and the display never points to a particular matching cell. We supplied that reasoning.
Check the scorer by reasoning backwards
Clear the board and submit 3456. Against 1122 it should give 0 EXACT and 0 OTHER. That tells us none of those four digits appears anywhere. It leaves only 1 and 2, but it does not tell us their counts or their order: 1111, 1122 and 2222 would all agree with that clue alone.
Explain why 1212 gives 2 EXACT and 2 OTHER against 1122 before submitting it. The first and fourth positions match; the remaining 1 and 2 can each be paired once elsewhere. Then try your own sequence and explain what each row rules out.
This visible-code exercise checks our interpretation of clues. It does not claim that three guesses will solve every hidden code. A useful guess can distinguish possibilities even when you do not expect it to be the answer.
Run it here
This unit's program, built for you.
- Program
- locksmith.tap
- Machine
- ZX Spectrum 48K (PAL)