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.
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.
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.
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.
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.
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.
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.
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.