Mõttemeister
InterviewTime limit1sMemory limit1024 MB
Given several guesses and their correct-digit counts A and position counts B, list every 4-digit secret number consistent with all clues.
- Level
Medium5 of 10
- Topics
- Brute force, Implementation, Simulation, Array
- Solved
- No attempts yet
Statement
Mõttemeister is a board game for two players. The first player thinks of a secret 4-digit number, and the second player tries to guess it.
On each turn the guesser proposes a 4-digit number. The first player answers with two values and , where is how many of the digits in the proposed number are correct, and is how many of those are also in the correct position.
The guesser then makes a new proposal, and the game continues until the guesser finds the secret number or the number of turns exceeds a given limit.
For example, suppose the secret number is . For the proposal the answer would be (the digits and are correct) and (the digit is in the correct position).
If a proposal contains repeated digits, each digit is counted as correct only as many times as it occurs in the secret number.
Write a program that, from the given proposals and answers, finds all possible values of the secret number.
Input
The first line contains an integer (). Each of the next lines describes one turn: the proposed 4-digit number, its count of correct digits (), and the count of those digits that are also in the correct position ().
Output
On the first line print the number of possible values of the secret number. On the next lines print the possible secret numbers in increasing order, one per line. Every number is printed with exactly four digits, padded with leading s if necessary.