184Games · Turn-based games

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
01

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
22, 40
Standard solution (without a calculator)
  1. Apply the stated rules in order.
  2. 5=5; 0=0; (8,7)↔(7,8) ⇒ 2A2B ⇒ 22
  3. 5078 ⇒ 4A0B ⇒ 40
  4. Output sequence: 22, 40
Do it on the calculator

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
−9, 40
Standard solution (without a calculator)
  1. Apply the stated rules in order.
  2. |{5,5,0,7}|=3<4 ⇒ −9
  3. 5078 ⇒ 4A0B ⇒ 40
  4. Output sequence: −9, 40
Do it on the calculator

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
0, 5078
Standard solution (without a calculator)
  1. Apply the stated rules in order.
  2. ∅: Leave the input blank and press EXE.
  3. {1,2,3,4}∩{5,0,7,8}=∅ ⇒ 0A0B ⇒ 0
  4. B=0 ⇒ 5078
  5. Output sequence: 0, 5078
Do it on the calculator
02

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.

Sign in to unlock the full programme

Checking access…

The programme code and appendix unlock together.

Checking access…

Sign in to unlock the full programme

Checking access…

The programme code and appendix unlock together.