Android's Locking Pattern
Join the DZone community and get the full member experience.Join For Free
for the rest of this discussion, i will use the following convention to designate a locking pattern:
- it needs to contain at least four dots (and obviously, no more than nine).
- once a dot is lit, it can't be used again.
you can use one or several "knight moves", such as in [0 5 4 2]:
in this example, the knight move is between 0 and 5.
- you cannot go over an unlit dot without lighting it. for example, the pattern [0 2 1 4] is illegal, because moving your finger between 0 and 2 will light 1.
once a dot is lit, you can use it to reach another unlit dot. for example, both [0 4 3 5] and [0 4 5 3] are legal:
this example is a bit ambiguous but you get the idea: i trace [0 4 5] and then i slide over 4 again to reach 3.
with these constraints in place, i wondered how many combinations were actually possible, so i wrote a short program to simulate it. it turns out there are quite a few: 389,112. here is a breakdown:
4 dots: 1624 solutions
5 dots: 7152 solutions
6 dots: 26016 solutions
7 dots: 72912 solutions
8 dots: 140704 solutions
9 dots: 140704 solutions
if you're not convinced, here is a full list of all the four dot patterns (the page 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...
Opinions expressed by DZone contributors are their own.