6.2. There are 7 safes and 7 codes for them, but it is unknown which code belongs to which safe. What is the minimum number of attempts required to guarantee matching the codes to the safes?
Answer: 21 attempts.

Solution. We enter the first code in sequence on each of the safes. If one of the safes opens - we leave this safe and the code. If none of the first 6 safes open, then this code corresponds to the seventh safe. No more than six attempts have been used, and there are 6 safes and 6 codes left. We take another code and enter it on all the safes in sequence. To determine which safe this code corresponds to, no more than 5 attempts are needed. And so on. In total, no more than $6+5+4+3+2+1$ = 21 attempts are required.