Problem 131388 · hard · Phase 01 Prerequisites & Setup

Referee for Strict Code-Breaker

strings · lists · loops · conditionals · functions

In the board game Code-Breaker one player hides a code secret made of the letters A to F (letters may repeat). The other player guesses codes of the same length. Each reply has two numbers: exact, the positions where guess and secret agree, and moved, the further letters that appear in both but in the wrong places (a letter counts only as often as it appears in both codes).

Club rules are strict. Write referee(secret, guesses, turns) that returns one reply string for each guess it processes:

  1. A guess of the wrong length or with any character other than A-F gets "INVALID".
  2. A guess is inconsistent if it could not be the secret given the replies so far: for some earlier accepted guess g, scoring g against this new guess (as if it were the secret) does not give the reply g really received. It gets "INCONSISTENT".
  3. Rejected guesses (rules 1 and 2) do not use a turn. Any other guess is accepted as turn t = 1, 2, .... If it equals the secret the reply is "WIN t"; otherwise it is "t: exact moved", for example "2: 1 3".
  4. The game ends at a win or right after the turns-th accepted guess. Guesses after the end get no reply at all.

Examples

Input:  secret = "ABCD", guesses = ["AABB", "abcd", "ACBB", "ABDC", "ABCD", "FFFF"], turns = 6
Output: ["1: 1 1", "INVALID", "INCONSISTENT", "2: 2 2", "WIN 3"]
Explanation: if ACBB were the secret, AABB would have scored 3 exact, not 1 exact 1 moved.

Input:  secret = "CAFE", guesses = ["BEAD", "CAF", "EACF", "CAFE"], turns = 2
Output: ["1: 0 2", "INVALID", "2: 1 3"]
Explanation: two turns are used up, so the final guess is never judged.

Constraints

  • 1 <= len(secret) <= 8; secret uses only A-F.
  • 0 <= len(guesses) <= 500, 1 <= turns <= 500; guesses may be any strings.

Goals

  • Score a guess with exact matches and shared letter counts
  • Reuse one scoring function in a second, less obvious role
  • Track game state (accepted guesses and replies) across many turns
Starting Python…