Four-Digit Code
Four-Digit Code
Guess a four-digit secret with four different digits. Zero is allowed after the first position; there is no automatic solver or guess counter.
- 381 bytes
- COMP mode
Worked examples
Example 1
Original game exercise. Assumed secret code: 5078. Input order: 5087 → 5078. Read the output sequence and explain the result. These examples assume the stated draws solely to explain a game. Ordinary play is random and will usually show different values; these inputs do not force the illustrated secret or cards.
Answer
Standard solution (without a calculator)
- Apply the stated rules in order.
- 5=5; 0=0; (8,7)↔(7,8) ⇒ 2A2B ⇒ 22
- 5078 ⇒ 4A0B ⇒ 40
- Output sequence: 22, 40
Example 2
Original game exercise. Assumed secret code: 5078. Input order: 5507 → 5078. Read the output sequence and explain the result. These examples assume the stated draws solely to explain a game. Ordinary play is random and will usually show different values; these inputs do not force the illustrated secret or cards.
Answer
Standard solution (without a calculator)
- Apply the stated rules in order.
- |{5,5,0,7}|=3<4 ⇒ −9
- 5078 ⇒ 4A0B ⇒ 40
- Output sequence: −9, 40
Example 3
Original game exercise. Assumed secret code: 5078. Input order: 1234 → ∅. Read the output sequence and explain the result. These examples assume the stated draws solely to explain a game. Ordinary play is random and will usually show different values; these inputs do not force the illustrated secret or cards.
Answer
Standard solution (without a calculator)
- Apply the stated rules in order.
- ∅: Leave the input blank and press EXE.
- {1,2,3,4}∩{5,0,7,8}=∅ ⇒ 0A0B ⇒ 0
- B=0 ⇒ 5078
- Output sequence: 0, 5078
When to use it
Guess a four-digit secret with four different digits. Zero is allowed after the first position; there is no automatic solver or guess counter. These examples assume the stated draws solely to explain a game. Ordinary play is random and will usually show different values; these inputs do not force the illustrated secret or cards.
Input order
- B?: an integer 1000–9999 with no repeated digits; 0 or blank EXE gives up and reveals the secret.
Output order
- 10A+B encodes exact-position matches A and wrong-position matches B: 22=2A2B; 0=0A0B. A displayed 0 is a score. Score 40 ends the game; giving up shows the secret. Invalid input gives −9.
Conditions and limitations
- Both secret and guess must have distinct digits. Count A by equal positions, then B by common digits minus A; do not count one digit twice. Invalid guesses do not change the secret.
- The program sets Fix 0, overwrites its registers and Ans, then returns to Norm 1 on normal completion. AC during play may leave Fix 0. Previous values and display settings are not restored. Registers can be inspected; there is no anti-cheating protection.
- Equal-likelihood claims assume independent equally likely Ran# grid values; no cryptographic security is claimed. When used, rejection sampling has no fixed maximum number of draws.
Checking access…