Bill has a problem. He has locked his pin in a strong box and forgotten the combination.
The lock uses all the digits 1 through 6 in some order. He has tried the following three combinations: 4-5-6-1-3-2 which has one digit correct; 6-2-3-4-5-1 which has two digits correct; and 2-3-1-6-4-5 which has three digits correct.
What is the combination?
Also brute force
ried:
4-5-6-1-3-2 one correct
6-2-3-4-5-1 two correct
2-3-1-6-4-5 three correct
The combination:
2, 5, 3, 6, 4, 1
-------
goodA = [4, 5, 6, 1, 3, 2]
goodB = [6, 2, 3, 4, 5, 1]
goodC = [2, 3, 1, 6, 4, 5]
digits1to6 = [k+1 for k in range(6)]
from itertools import permutations
for p in permutations(digits1to6):
correct = 0
for i,v in enumerate(p):
if v == goodA[i]:
correct += 1
if correct != 1:
continue
correct = 0
for i,v in enumerate(p):
if v == goodB[i]:
correct += 1
if correct != 2:
continue
correct = 0
for i,v in enumerate(p):
if v == goodC[i]:
correct += 1
if correct != 3:
continue
print(p)
|
Posted by Larry
on 2025-01-24 10:35:55 |