September 17, 2008Android's locking pattern
As you might already know, Android uses an innovative approach to lock your phone and prevent accidental dialing. Play the short video above to see how it works. For the rest of this discussion, I will use the following convention to designate a locking pattern:
4 dots: 1624 solutions 5 dots: 7152 solutions 6 dots: 26016 solutions 7 dots: 72912 solutions 8 dots: 140704 solutions 9 dots: 140704 solutions Total: 389112If you're not convinced, here is a full list of all the four dot patterns (the page only works on Firefox and it uses a big canvas object, it might take a few seconds to load). Still, I'm not sure my calculations are right, so I'd like you, dear reader, to confirm my numbers, and optionally explain how you coded your solution... Comments
Would [5 0 2 1] be a valid 4 dot solution? Elided from [5 0 5 2 1] using a combination of the 3rd and 5th rules? I don't see it in your list though? If it is valid then I'm getting figures such as: 4 dots: 2352 solutions And for completeness: 2 dots: 56 solutions (I know this one is right :-)) Nice small multiples diagram! This unlock system looks cool, but it sure seems less secure than a PIN and no easier to remember. Posted by: Nelson at September 18, 2008 07:10 AM@Charles: I don't believe that's the meaning of the fifth rule. In fact, I think rule 5 is redundant with rule 4. Rule 3 may be redundant as well. I would restate the rules as follows: * A path must visit at least four dots. I can confirm those results, by means of a rather brute force search. I first created a function that takes the current dot and a set of all visited dots and reports which dots may be visited next. I further broke this down into "easy" cases and "hard" cases. For each dot, there is a set of dots that you can *always* visit next so long as you have not visited them before. These are the easy cases and can trivially be stored in a short table. The hard cases are the dots that can only be visited if the dot in the way has been visited first. For the corner dots, there are three such candidates, the dots in the other corners. For the dots in the middle of an edge, the candidate dot is the opposite dot. In all cases, the "blocking" dot is in between the two. The candidate dot can be visited next only when the blocking dot *is* in the visited set and the candidate dot *is not* in the visited set. Once you have that function, it's easy to do a brute force search in a depth-first manner. There are some obvious ways to exploit the symmetry to chop down the search time a bit, and you can do most of the set operations with bitwise operations, but I'd be interested to know if there's a more elegant algorithm. I don't exploit the fact that, for example, the sets of possible suffixes for each of the prefixes 0134, 0314, 1034, 1304, 3014, 3104 are all identical. Posted by: Weeble at September 19, 2008 09:07 AMMy implementation could be cleaner, and given that it appears to run instantaneously, the bit twiddling optimisation may have been completely unnecessary. Still, hopefully it's not completely indecipherable. I put the code in pastebin, but it seems I can't post the URL here. I'll try without the prefix: pastebin.com/f6e4a1689 Posted by: Weeble at September 22, 2008 08:08 AMThis was the reason of the "code challenge"? Cool Posted by: Oscar Reyes at October 11, 2008 03:32 PMbeautifull Posted by: Ian at October 13, 2008 12:45 PMI like the page with all possible combinations using 4 dots. You should post one showing all combinations using all 9 dots, or maybe just all possible combos! That would be SWEET!!! Posted by: J at October 31, 2008 12:57 AMPost a comment
|