Ever since the notorious jewel thief Rough Diamond's humble beginning as a tiny talking horse, she grew into burglary at a frankly alarming rate. She was branded a 'difficult filly', largely because of her penchant for making the school lunches of her fellow classmates suddenly disappear, and no amount of reinforcement, positive or otherwise, managed to dissuade her from stealing the school roof right before graduation.
Her track record had done her no favours when it came to higher education, but far too young and grossly under-qualified and with a sense of guile as big as hers, she was able to use every dirty trick and low-down swindle she could think of to major in Particle Physics and minor in Kleptomania at Manehatten University.
Clutching her new degree in her sweaty hooves, she would go on to mastermind her first bank heist, disguised as Princess Luna (a particularly daring gambit, as Luna hadn't even returned from the moon at the time and nopony recognised her...or perhaps that was exactly why she succeeded), and the theft of Trottingham - as in, the city, yeah, she stole a city - sealing her reputation as one of the most brilliant jewel thieves in all of Equestria.
It is during one such heist that we find Rough Diamond, trying to crack open a safe. As it happens, her plans for the night actually created a schedule overlap with another aspiring jewel thief - she caught him trying to crack it open earlier, but Rough Diamond managed to scare him off by pointing a banana at his head, and he laughed at first, before he would learn to his cost that the banana was in fact loaded.
Turning her attention to the safe. Rough Diamond sees that he's been attempting to open the safe by inserting three different keys into three different locks. Looking over the safe's mechanisms, she sees a large button next to the key locks reading "Attempt to Open". She deduces that once all the keys have unlocked all the locks, the button needs to be pressed in order to gain access to the valuable contents within.
However, the problem soon proves to be trickier than imagined. Rough Diamond has no idea what state the locks are in after the first intruder left, and the locks seem to function independently, so no hope of fiddling with one to hit a reset button for her. What's more, she cannot fiddle with a lock to figure out if it's locked or not, as the lock is one where the key doesn't need to be turned to change its state.
She doesn't have all night. She reckons as long as she goes through the right number of sequences, she should be able to get the safe open eventually, but how long would that take?
Steal the safe and open it later. After all, if she stole an entire CITY, and a roof, a safe should be no problem.
Considering its not open now, im gonna say the starting state has minimum 1 in the locked position
now no matter what, if we use the same key on a lock twice, they stay the same state(either not changing or switch between lock/unlock & back)
Otherwise i need to ask, if we use the correct key on a lock, will we know the state is changed?
is it 7?
9234690
There's no audible or visible difference. You'll only know if they're unlocked once you've got the safe open
try each key in the following combos
123,231,312,132,213,321 it must open at some point as one of these is the exact combo that changes all 3, and all other ones cover when its in any status
WARNING: GIANT WALL OF TEXT APPROACHING
I can get the number of attempts down to 12.
Stick the keys into the locks in the following order: ABC, BCA, CAB, ABC, BCA, ABC, ACB, BAC, ACB, CBA, BAC, ACB.
There are six possible ways for the three keys to affect the three locks - ABC, ACB, BAC, BCA, CAB, and CBA. Let's divide these six ways into two groups: ABC/BCA/CAB and ACB/BAC/CBA. The important thing to note here is that for any given key and any given lock, the two states where that key affects that lock are in opposite groups - for example, for key A and lock 2, BAC is in the second group while CAB is in the first. This means that if we stick in the three keys in one particular way, that state will have all three locks flipped, the other states in that group will have no locks flipped, and the three states in the other group will have exactly one lock flipped.
With that in mind, let's look at my solution. First, let's look at the states from the second group - those where the locks are ACB, BAC, and CBA. Let's use ACB as an example - BAC and CBA will work out the same way. First, lock 1 is flipped, so if that was the only one locked we're done. Then lock 2 is flipped, so if the locked ones were 1 and 2 we're done. Then lock 3 is flipped, so if all three locks were locked then we're done. Then lock 1 is flipped back, so if the locked ones were 2 and 3 we're done. Then lock 2 is flipped back, so if the only locked one was 3 then we're done. Then lock 1 is flipped again, so if the locked ones were 1 and 3 we're done. The only way we haven't unlocked the safe yet is if the lock flipped in the second attempt - lock 2 in this case - was the only one locked at first. But if that's the case, then since locks 1 and 3 have been flipped overall, then all locks are currently locked. This is the case for all three states - if they haven't been unlocked yet, then all three locks are currently locked, so at some point in the next six attempts, when that state is chosen, all three locks will be unlocked, and the safe will open.
What about the states from the first group - ABC, BCA, and CAB? In each of the first six attempts, the locks are either unaffected or all flipped. Since each state is flipped at least once, no matter which state is the real one, the locks aren't all locked, otherwise the safe would've opened by now. There must be either one or two locks left locked. So let's watch what happens to ABC (BCA and CAB will be similar). First lock 1 is flipped, opening the safe if only 1 was locked. Then lock 3 is flipped, opening the safe if 1 and 3 were locked. Then lock 1 is flipped, opening the safe if only 3 was locked. Then lock 2 is flipped, opening the safe if 2 and 3 were locked. Then lock 3 is flipped, opening the safe if only 2 was locked. Finally lock 1 is flipped, opening the safe if 1 and 2 were locked. No matter which lock or locks were still locked after the first six attempts, the next six will open the safe.
Incidentally, I can actually prove that 12 can't be improved:
Ignoring the solved state where all locks are unlocked, there are 7 states for the locks and 6 states for the keys, making 42 states overall. Each attempt will solve at most 4 states if all three keys are used - using two keys will only affect 3 states, and using one key will only affect 2 states. So after 10 attempts, at most 40 states can be solved. Therefore, at least 11 attempts are necessary.
Suppose we had a solution involving 11 attempts. There are only four possibilities: Either there were 10 triple-key attempts and one single-key attempt, 9 triple-key attempts and 2 double-key attempts, 10 triple-key attempts and 1 double-key attempt, or 11 triple-key attempts. (Anything else wouldn't reach the 42 states necessary.) Now, each key states requires at least 7 changes to be unlocked, so for any given key state, there are at most 4 attempts that do not change it. So, for either group of states, there are at most (4*3)/2 = 6 triple-key attempts using a state from that group. So in the case of 11 triple-key attempts, one group has 6, which would need to be split 2-2-2, and one group has 5, which could be split 3-1-1 or 2-2-1. Double-key attempts can be counted as triple-key attempts, but as they keep one member of the opposite group the same as well, they must be in the group of 6. Single-key attempts are even more restrictive, they would technically fall in both groups, meaning each group would then need 5 triple-key attempts.
In the case of a single-key attempt, let's assume that it's using key A on lock 1 (the argument generalizes to any key in any lock). It will only change states ABC and ACB, and keep all the others the same. That means that BAC, BCA, CAB, and CBA each have only three triple-key attempts that do not change them (that is, the attempt is another state from the same group). The only way to satisfy this restriction is for the eleven attempts to be, in some order, A-- ABC ACB BAC BAC BCA BCA CAB CAB CBA CBA. Now, look at what happens with state ABC. In four attempts (BCA, BCA, CAB, CAB) it stays the same, so let's ignore those. Two attempts (A-- and ACB) flip only lock 1, two attempts (CBA and CBA) flip only lock 2, two attempts (BAC and BAC) flip only lock 3, and one attempt (ABC) flips all three locks. What we would have to do is find a way to reach all seven sets of flips using only these seven kinds of flips. Since each lock is flipped three times, the end position must be having all three locks flipped. The other six possibilities are connected in a ring of single-flip changes (1 only, 1 and 2, 2 only, 2 and 3, 3 only, 1 and 3, then back to 1 only), with the triple-flip jumping to the opposite side of the ring. The only way to even reach all six possibilities in the ring while including that triple-flip is to reach the first three spots, then flip and reach the other three.
But if you do that, you won't do each single-flip two times (for example, you could go 1, 1 and 2, 2, triple-flip to 1 and 3, 3, 2 and 3, but then you're only flipping lock 3 once and in the end you'll flip lock 1 five times). Therefore, this case is impossible.
In any other case, consider the group of key states with 5 attempts. Whether the flips land 3-1-1 or 2-2-1, some state must only be used once - again, without loss of generalization, let's refer to it as ABC. The other four attempts in this group will have no effect, so the only seven attempts that do are this one (ABC) and the six in the other group. Now, for each attempt in the other group, whether it is a triple-key attempt or a double-key attempt, it will only affect one state in that group, so by the same argument as before the attempts must split 2-2-2. That means that since they all have to affect state ABC, the seven flips of state ABC are, as before, lock 1 twice, lock 2 twice, lock 3 twice, and all three locks once. But by the argument in the last paragraph, this is impossible to do. Therefore, however they are arranged, it's impossible for 11 attempts to always succeed.
If there's a case where my solution fails, please let me know.
The locks may all be in either of the two states: locked or unlocked. Therefore there are 2^3 = 8 combinations the locks are.
Only one combination of the keys is correct. The keys may not repeat (obviously!) and are to be inserted in a specific order. There are 3 * 2 * 1 = 6 ways to arrange the keys.
Not only have we got to guess the right combination, but to make sure all of the locks are unlocked as well! Suppose, we guessed (odds are 1/6), then we have to toggle each lock. They may have been unlocked by now.
Let us denote "unlocked" by "u", and "locked" by "l" and proceed to toggling:
Uuu -- uul -- ulu -- ull -- luu -- lul -- llu -- lll;
To traverse each state, we must do the toggling 8 times. After that, if the safe is not opened, we try to apply the next combination of keys. Of course, some times we may be trying in vain, as the keys won't even change the locks' state, or will just that of one lock. But, once we hit the right combination (which may happen to be the last one ), we must just try 8 more times.
So we'd need 6 * 8 = 48 attempts, if we are just so unlucky. Since the previous thief may have tried at least once to unlock the safe, there may be just 47 attempts for us.