3 ms·
I'm no mathematician or leetcode expert and probably don't understand "shortest possible test sequence", but it sounds like this is just bruteforcing 0000-9999.
by Cthulhu_ 2y ago
I'm no mathematician or leetcode expert and probably don't understand "shortest possible test sequence", but it sounds like this is just bruteforcing 0000-9999. You can't guess what would be closer to the correct solution, so at best I'd propose making a list of choices and randomizing the tries in case you get lucky.
It's different if the keypad gives an indication that one number is correct though, then it'll be 40 tries at most.
- fuglede_ 2y agoThe point is that if you input, say, 00001, then you will have tested both 0000 and 0001.
- CJefferson 2y agoIf the code is either 0000 or 0001, then entering 00001 will open the door, as you just need the four digits in order. That shows how you can do a shorter sequence by using overlaps.
- Biganon 2y agoHave you read the article we're commenting on? Obviously mathematicians know that n! * k, with k the length of the code, would work. The idea is to superpose the end of a code with the start of the next, so you don't have to test nearly as many combinations.