Skip to main content
added 567 characters in body
Source Link
d'alar'cop
  • 12.9k
  • 4
  • 50
  • 91

I arrived at a relatively simple answer which assumes that one is not "clever" about cutting down the search space with strategic guesses. I'll discuss that a little more at the end.

The probability of choosing a winning combination is:

$( {M \choose M} + {M \choose M-1} )/ {N \choose M}$

i.e. The sum of either choosing all the numbers correctly and choosing all but one correctly. For your little example, this is $(1 + 3)/4 = 1$ - so you're guaranteed to win.

So, to answer the question itself, you would need to exhaust all the non-winning combinations first then the next one wins i.e. : ${N \choose M} - ( {M \choose M} + {M \choose M-1} )+1$ minimum attempts to guarantee unlocking.

Now, your challenge is essentially the game Mastermind where N is the number of colours and M is the length of the code (with no repeats) and a win only requires M-1 (or M) pegs of any colour. The cumulative efforts of the world's minds have not come up with a neat formula for this, but Knuth came up with a 5-move strategy for standard Mastermind.

I arrived at a relatively simple answer.

The probability of choosing a winning combination is:

$( {M \choose M} + {M \choose M-1} )/ {N \choose M}$

i.e. The sum of either choosing all the numbers correctly and choosing all but one correctly. For your little example, this is $(1 + 3)/4 = 1$ - so you're guaranteed to win.

So, to answer the question itself, you would need to exhaust all the non-winning combinations first then the next one wins i.e. : ${N \choose M} - ( {M \choose M} + {M \choose M-1} )+1$ minimum attempts to guarantee unlocking.

I arrived at a relatively simple answer which assumes that one is not "clever" about cutting down the search space with strategic guesses. I'll discuss that a little more at the end.

The probability of choosing a winning combination is:

$( {M \choose M} + {M \choose M-1} )/ {N \choose M}$

i.e. The sum of either choosing all the numbers correctly and choosing all but one correctly. For your little example, this is $(1 + 3)/4 = 1$ - so you're guaranteed to win.

So, to answer the question itself, you would need to exhaust all the non-winning combinations first then the next one wins i.e. : ${N \choose M} - ( {M \choose M} + {M \choose M-1} )+1$ minimum attempts to guarantee unlocking.

Now, your challenge is essentially the game Mastermind where N is the number of colours and M is the length of the code (with no repeats) and a win only requires M-1 (or M) pegs of any colour. The cumulative efforts of the world's minds have not come up with a neat formula for this, but Knuth came up with a 5-move strategy for standard Mastermind.

Post Undeleted by d'alar'cop
Post Deleted by d'alar'cop
Post Undeleted by d'alar'cop
deleted 99 characters in body
Source Link
d'alar'cop
  • 12.9k
  • 4
  • 50
  • 91

There are: ${N \choose M}$ possible codes. ${N \choose M-1}$ codes that you would try. ${M \choose M-1}$ codes that you can enter that would open the the lockI arrived at a relatively simple answer.

${N \choose M-1}$-${M \choose M-1}$ codes that you would enter will not help you. And as soon as they are exhausted you would be trying The probability of choosing a winning combination which will open the lock.is:

So the answer is: the minimum "smart" tries to guarantee opening$( {M \choose M} + {M \choose M-1} )/ {N \choose M}$

i.e. The sum of either choosing all the locknumbers correctly and choosing all but one correctly. For your little example, this is: ${N \choose M-1}$$(1 + 3)/4 = 1$ -${M \choose M-1}$ + 1 so you're guaranteed to win.

I came up with this asSo, to answer the language expressingquestion itself, you would need to exhaust all the codesnon-winning combinations first then the next one wins i. I added it here because I didn't want to waste ite. : $\{w \in \Sigma*| w = x_1x_2\cdots x_m \land x_i \in \Sigma \land |\Sigma| = n \}$ ${N \choose M} - ( {M \choose M} + {M \choose M-1} )+1$ minimum attempts to guarantee unlocking.

There are: ${N \choose M}$ possible codes. ${N \choose M-1}$ codes that you would try. ${M \choose M-1}$ codes that you can enter that would open the the lock.

${N \choose M-1}$-${M \choose M-1}$ codes that you would enter will not help you. And as soon as they are exhausted you would be trying a combination which will open the lock.

So the answer is: the minimum "smart" tries to guarantee opening the lock is: ${N \choose M-1}$-${M \choose M-1}$ + 1

I came up with this as the language expressing the codes. I added it here because I didn't want to waste it: $\{w \in \Sigma*| w = x_1x_2\cdots x_m \land x_i \in \Sigma \land |\Sigma| = n \}$

I arrived at a relatively simple answer.

The probability of choosing a winning combination is:

$( {M \choose M} + {M \choose M-1} )/ {N \choose M}$

i.e. The sum of either choosing all the numbers correctly and choosing all but one correctly. For your little example, this is $(1 + 3)/4 = 1$ - so you're guaranteed to win.

So, to answer the question itself, you would need to exhaust all the non-winning combinations first then the next one wins i.e. : ${N \choose M} - ( {M \choose M} + {M \choose M-1} )+1$ minimum attempts to guarantee unlocking.

Post Deleted by d'alar'cop
Source Link
d'alar'cop
  • 12.9k
  • 4
  • 50
  • 91

There are: ${N \choose M}$ possible codes. ${N \choose M-1}$ codes that you would try. ${M \choose M-1}$ codes that you can enter that would open the the lock.

${N \choose M-1}$-${M \choose M-1}$ codes that you would enter will not help you. And as soon as they are exhausted you would be trying a combination which will open the lock.

So the answer is: the minimum "smart" tries to guarantee opening the lock is: ${N \choose M-1}$-${M \choose M-1}$ + 1

I came up with this as the language expressing the codes. I added it here because I didn't want to waste it: $\{w \in \Sigma*| w = x_1x_2\cdots x_m \land x_i \in \Sigma \land |\Sigma| = n \}$