Page 1 of 1

Code puzzle

Posted: Wed Jul 16, 2014 7:29 am
by Ben Wilson
A door has an electronic code lock, where the code is always 3 digits between 1 and 5 inclusive. Repeat digits are not allowed, so whilst 423 is a valid code, 433 isn't. However, the door is set up to only recognise the last three digits entered. This means that if the code was 423 and you entered 15423, the door would unlock.

The question is: what is the fewest digits needed to run through all possible combinations and unlock the door, and what would that string of digits look like?

(Btw, I don't actually know the answer to this one myself)

Re: Code puzzle

Posted: Wed Jul 16, 2014 8:46 am
by Ryan Taylor
Just to clarify your example, does this mean that if you were to type "15423" then the lock would recognise the three digit combinations of "154", "542" and "423"?

Re: Code puzzle

Posted: Wed Jul 16, 2014 12:42 pm
by Ben Wilson
Ryan Taylor wrote:Just to clarify your example, does this mean that if you were to type "15423" then the lock would recognise the three digit combinations of "154", "542" and "423"?
Yes, in that order.

Re: Code puzzle

Posted: Wed Jul 16, 2014 12:44 pm
by Graeme Cole
What do you mean by "repeat digits"? The same digit twice consecutively, or the same digit twice anywhere in the code?

For example, is it valid for the code to be 343?

Re: Code puzzle

Posted: Wed Jul 16, 2014 2:04 pm
by Bob De Caux
Graeme, I interpreted it to mean no repeated digits anywhere within the three (the repeated digits case would be substantially easier, I think). Hopefully that is the case, as I found quite a neat way to do this. The sequence below is a minimum solution (i.e. solves all 60 codes using 62 digits), but is by no means unique.

2, 3, 1, 2, 4, 1, 2, 5, 1, 3, 2, 1, 3, 4, 1, 3, 5, 1, 4, 2, 1, 4, 3, 1, 5, 4, 1, 5, 2, 1, 5, 3, 1, 4, 5, 1, 2, 3, 5, 2, 4, 5, 2, 3, 4, 5, 3, 4, 2, 5, 3, 2, 4, 3, 5, 4, 3, 2, 5, 4, 2, 3

Re: Code puzzle

Posted: Wed Jul 16, 2014 2:11 pm
by Gavin Chipper
I think I saw a YouTube video on this once. Either Numberphile or Singingbanana or something.

Re: Code puzzle

Posted: Wed Jul 16, 2014 5:18 pm
by Charlie Reams

Re: Code puzzle

Posted: Wed Jul 16, 2014 9:04 pm
by Bob De Caux
Nice, could see it had something to do with Hamiltonian paths and presumed there must be a neat mathematical approach. Surprised I've never come across it before, actually.

Re: Code puzzle

Posted: Wed Jul 16, 2014 10:48 pm
by Gavin Chipper
This was the puzzle I was thinking of on YouTube and the solution.