Code puzzle

Cerebral distractions of every kind, mostly but not exclusively Countdown-related.

Moderator: Michael Wallace

Post Reply
User avatar
Ben Wilson
Legend
Posts: 4539
Joined: Fri Jan 11, 2008 5:05 pm
Location: North Hykeham

Code puzzle

Post 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)
Ryan Taylor
Postmaster General
Posts: 3661
Joined: Sun Oct 25, 2009 6:18 pm

Re: Code puzzle

Post 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"?
User avatar
Ben Wilson
Legend
Posts: 4539
Joined: Fri Jan 11, 2008 5:05 pm
Location: North Hykeham

Re: Code puzzle

Post 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.
User avatar
Graeme Cole
Series 65 Champion
Posts: 2025
Joined: Tue Jul 06, 2010 9:59 pm

Re: Code puzzle

Post 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?
Bob De Caux
Enthusiast
Posts: 265
Joined: Wed Sep 09, 2009 3:18 pm

Re: Code puzzle

Post 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
Gavin Chipper
Post-apocalypse
Posts: 13213
Joined: Mon Jan 21, 2008 10:37 pm

Re: Code puzzle

Post by Gavin Chipper »

I think I saw a YouTube video on this once. Either Numberphile or Singingbanana or something.
User avatar
Charlie Reams
Site Admin
Posts: 9494
Joined: Fri Jan 11, 2008 2:33 pm
Location: Cambridge
Contact:

Re: Code puzzle

Post by Charlie Reams »

Bob De Caux
Enthusiast
Posts: 265
Joined: Wed Sep 09, 2009 3:18 pm

Re: Code puzzle

Post 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.
Gavin Chipper
Post-apocalypse
Posts: 13213
Joined: Mon Jan 21, 2008 10:37 pm

Re: Code puzzle

Post by Gavin Chipper »

This was the puzzle I was thinking of on YouTube and the solution.
Post Reply