Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hi Can Anyone Help With A Calculation

Status
Not open for further replies.

rmn_tech

Member
A friend has constructed a simple electronic lock and I was trying to explain that it is not as secure as he thinks. It is a 4 digit entry code (digits 0 - 9) he thinks that there are 10,000 combinations (0000 - 9999)

However he has not taken into account that no digit can be used more than once in the unlock code, e.g. 1757 (2 x 7's) etc

Also the code can be entered in any order, e.g 1234 (can be entered as 4321, 2314, 3214, etc.)

What I am trying to work out is how many individual unique codes are available for use.

Recap

4 Digit code

digits from 0 to 9

no digit can be repeated in the code

no code can contain the same digits in different orders.

I don't expect anyone to work this out for me. I would however appreciate it if one of you good people could give me a formula or some clues to help me work this out.

Thanks in advance.

Rick.
 
Thanks Eric for your reply.

But the Lycos thread page as directed does not take into account that no digit can be repeated and no combination can contain the same 4 digits in a different order.

The calculation I have worked out for no combination having 2 or more of the same digit is: 10 x 9 x 8 x 7 = 5040 (comments)

However out of these 5040 many will have the same digits in a different order (e.g. 9876, 7869, 8796, 7698 and e.t.c.)

I now need to work out how to filter these out to arrive at the final number.

Blueroom I will check out your reply.

Thanks all for your interest.

Rick
 
Thanks Blueroom.

The first Google hit was very helpful.

From what I can gather as it is 4 digits

Then: 4 x 3 x 2 x 1 = 24

Therefore 5040 / 24 = 210

so the total amount of combinations that can be used is 210.

Please feel free to correct me if I am wrong.

Rick
 
Hi again Blueroom.

After checking the site you provided there is an example of the exact thing I needed and my calculation was correct at 210.

All I need now is to work out a program to list them all. Just out of curiosity.

All The Best Rick.

(Sorry missed your edit)
 
Last edited:
I will work on it just for something to do on a cold winter evening.

Regards.

Rick.
 
Hi,


I did a brute force search and found 210 combinations given the
restrictions posted previously.

Here is the list of all the combinations i found:

Code:
{
  {0,1,2,3},
  {0,1,2,4},
  {0,1,2,5},
  {0,1,2,6},
  {0,1,2,7},
  {0,1,2,8},
  {0,1,2,9},
  {0,1,3,4},
  {0,1,3,5},
  {0,1,3,6},
  {0,1,3,7},
  {0,1,3,8},
  {0,1,3,9},
  {0,1,4,5},
  {0,1,4,6},
  {0,1,4,7},
  {0,1,4,8},
  {0,1,4,9},
  {0,1,5,6},
  {0,1,5,7},
  {0,1,5,8},
  {0,1,5,9},
  {0,1,6,7},
  {0,1,6,8},
  {0,1,6,9},
  {0,1,7,8},
  {0,1,7,9},
  {0,1,8,9},
  {0,2,3,4},
  {0,2,3,5},
  {0,2,3,6},
  {0,2,3,7},
  {0,2,3,8},
  {0,2,3,9},
  {0,2,4,5},
  {0,2,4,6},
  {0,2,4,7},
  {0,2,4,8},
  {0,2,4,9},
  {0,2,5,6},
  {0,2,5,7},
  {0,2,5,8},
  {0,2,5,9},
  {0,2,6,7},
  {0,2,6,8},
  {0,2,6,9},
  {0,2,7,8},
  {0,2,7,9},
  {0,2,8,9},
  {0,3,4,5},
  {0,3,4,6},
  {0,3,4,7},
  {0,3,4,8},
  {0,3,4,9},
  {0,3,5,6},
  {0,3,5,7},
  {0,3,5,8},
  {0,3,5,9},
  {0,3,6,7},
  {0,3,6,8},
  {0,3,6,9},
  {0,3,7,8},
  {0,3,7,9},
  {0,3,8,9},
  {0,4,5,6},
  {0,4,5,7},
  {0,4,5,8},
  {0,4,5,9},
  {0,4,6,7},
  {0,4,6,8},
  {0,4,6,9},
  {0,4,7,8},
  {0,4,7,9},
  {0,4,8,9},
  {0,5,6,7},
  {0,5,6,8},
  {0,5,6,9},
  {0,5,7,8},
  {0,5,7,9},
  {0,5,8,9},
  {0,6,7,8},
  {0,6,7,9},
  {0,6,8,9},
  {0,7,8,9},
  {1,2,3,4},
  {1,2,3,5},
  {1,2,3,6},
  {1,2,3,7},
  {1,2,3,8},
  {1,2,3,9},
  {1,2,4,5},
  {1,2,4,6},
  {1,2,4,7},
  {1,2,4,8},
  {1,2,4,9},
  {1,2,5,6},
  {1,2,5,7},
  {1,2,5,8},
  {1,2,5,9},
  {1,2,6,7},
  {1,2,6,8},
  {1,2,6,9},
  {1,2,7,8},
  {1,2,7,9},
  {1,2,8,9},
  {1,3,4,5},
  {1,3,4,6},
  {1,3,4,7},
  {1,3,4,8},
  {1,3,4,9},
  {1,3,5,6},
  {1,3,5,7},
  {1,3,5,8},
  {1,3,5,9},
  {1,3,6,7},
  {1,3,6,8},
  {1,3,6,9},
  {1,3,7,8},
  {1,3,7,9},
  {1,3,8,9},
  {1,4,5,6},
  {1,4,5,7},
  {1,4,5,8},
  {1,4,5,9},
  {1,4,6,7},
  {1,4,6,8},
  {1,4,6,9},
  {1,4,7,8},
  {1,4,7,9},
  {1,4,8,9},
  {1,5,6,7},
  {1,5,6,8},
  {1,5,6,9},
  {1,5,7,8},
  {1,5,7,9},
  {1,5,8,9},
  {1,6,7,8},
  {1,6,7,9},
  {1,6,8,9},
  {1,7,8,9},
  {2,3,4,5},
  {2,3,4,6},
  {2,3,4,7},
  {2,3,4,8},
  {2,3,4,9},
  {2,3,5,6},
  {2,3,5,7},
  {2,3,5,8},
  {2,3,5,9},
  {2,3,6,7},
  {2,3,6,8},
  {2,3,6,9},
  {2,3,7,8},
  {2,3,7,9},
  {2,3,8,9},
  {2,4,5,6},
  {2,4,5,7},
  {2,4,5,8},
  {2,4,5,9},
  {2,4,6,7},
  {2,4,6,8},
  {2,4,6,9},
  {2,4,7,8},
  {2,4,7,9},
  {2,4,8,9},
  {2,5,6,7},
  {2,5,6,8},
  {2,5,6,9},
  {2,5,7,8},
  {2,5,7,9},
  {2,5,8,9},
  {2,6,7,8},
  {2,6,7,9},
  {2,6,8,9},
  {2,7,8,9},
  {3,4,5,6},
  {3,4,5,7},
  {3,4,5,8},
  {3,4,5,9},
  {3,4,6,7},
  {3,4,6,8},
  {3,4,6,9},
  {3,4,7,8},
  {3,4,7,9},
  {3,4,8,9},
  {3,5,6,7},
  {3,5,6,8},
  {3,5,6,9},
  {3,5,7,8},
  {3,5,7,9},
  {3,5,8,9},
  {3,6,7,8},
  {3,6,7,9},
  {3,6,8,9},
  {3,7,8,9},
  {4,5,6,7},
  {4,5,6,8},
  {4,5,6,9},
  {4,5,7,8},
  {4,5,7,9},
  {4,5,8,9},
  {4,6,7,8},
  {4,6,7,9},
  {4,6,8,9},
  {4,7,8,9},
  {5,6,7,8},
  {5,6,7,9},
  {5,6,8,9},
  {5,7,8,9},
  {6,7,8,9}
}

Total=210
 
But those are all in numerical order - any lock worth calling one would allow them in different order as well, which would greatly increase the number of choices. For that matter, it would also allow multiple digits, and introduce time delays after a number of failed attempts.
 
Hi
210= 10!÷(6!×4!) i.e 10 C 4 in Combinatrics
 
Hi again.

Nigel, that is the point I was trying to make to my friend.


Thanks to all you guys on this forum I am now armed with the proof I need to tell build a better lock.

Thanks Guys.

Oh and thanks for the listing.

Best Wishes.

Rick.
 
Last edited:
I thought the same but the first thread indicates it doesn't matter what order they're entered so only 210 combination's are possible.

I don't really see how you could build a lock that didn't care what order the digits were in? - even the simple four mechanical rotary switches cares what order the digits are in.
 
Hi Nigel.

I will try to obtain the circuit from my friend and will post it here. I too have difficulty trying to imagine a workable system using these restrictions.

There are however none electronic mechanical locks that do have these restrictions. There are small 'key safes' on the market that you are supposed to attach outside your locked door in which you place the door key for people who know the code to open the door.

Very secure I'm sure.

Be Lucky.
Stay Happy.

Rick.
 
I don't really see how you could build a lock that didn't care what order the digits were in? - even the simple four mechanical rotary switches cares what order the digits are in.

Exactly!



210 is too low.

1254 is not the same as 5124, they cannot be considered repetitions.

So, in this case, you'll have permutation (because order does matter) without repetition:

You have 10 digits (0,1,2,3,4,5,6,7,8,9). If you do not want any of them to repeat, (for example, you'll not have 7758):

10*9*8*7 = 5040 combinations, this is the worst case.

The best case is 10^4 = 10.000.

And the intermediate case, where you do not want to have a just repeated numbers like (0000, 1111 , ... , 9999). Just imagine a matrix, the repeated numbers will be the diagonal.

10^4 - 10 = 9090.
 
I don't see how your program will NOT differentiate between correct combination and incorrect combination both containing the same four digits? i.e. If the combination is 1234 and you type in 4321 into the 'keypad?' will the program just ensure the correct four digits are contained in the array or will each element of the array be matched to a prescribed ordered combination? If it is the latter then you can have a maximum of 5040 (10! / 6!) combinations however, if it is the former which would turn out to be more work then it is worth would produce 210 (10! / [4! * 6!]) combinations and an obviously less secure keylock.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top