code, and the other tries to guess it by naming a string attempt of the same length. The guesser gets a hint back:
- how many digits are right and in the right position; call them **exact**;
- how many more digits of the attempt appear in the code but in other positions. Precisely, it is the largest number of the remaining (non-exact) attempt digits that could be rearranged to become exact. Each digit of the code counts at most once.
Return the hint as the string "xAyB", where x is the number of exact digits and y the number of digits found in the wrong place. Both code and attempt may contain repeated digits.code='2468', attempt='8462' → '2A2B'
4 and 6 are in the right places. 8 and 2 are in the code but elsewhere, giving 2A2B.
code='5500', attempt='0055' → '0A4B'
No digit is in place, yet all four can be rearranged to match: 0A4B.
code='112', attempt='211' → '1A2B'
The middle 1 is in place. Of the remaining "12" and "21", both digits occur in the code but in other places: 1A2B.
code and attempt consist of digits onlycode='2468', attempt='8462'
'2A2B'
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.