#267 · Games and puzzles · Intermediate · 60 XP · about 12 min
In a code-breaking game one player hides a secret row of coloured pegs and the other tries to guess it. Colours are single capital letters and may repeat, so 'RGGB' is a red, two greens and a blue. After each guess the code keeper gives two clues:
Write clues(secret, guess) that returns the tuple (exact, colour_only). Both strings have the same length.
clues('RGBY', 'RGBY') # returns (4, 0) clues('RGBY', 'YBGR') # returns (0, 4) clues('RGGB', 'GGRR') # returns (1, 2) clues('AABB', 'BBBB') # returns (2, 0)
In the third example the green in position 1 is exact. The secret's other pegs are R, G and B, and the guess's other pegs are G, R and R: the G matches the secret's spare green and one R matches its red, but the second R has nothing left to match, so the colour-only clue is 2.
First solves only, ranked by stars and then time.