# What is the number of pattern locks possible for n × n grid?

What is the general formula to find the number of pattern locks possible for n × n grid?

Rules are quite identical to what phone lockscreen has.

• Dots cannot be used more than once.

• Length of a pattern can be greater than or equal to one.

• You can't for instance go from (1,1) to (1,4) without hitting (1,2) & (1,3).

• Is there a similar question asked? Sep 14, 2017 at 19:32
• Your question is very difficult to understand, and it may help to provide some explanation of what these rules mean. Are you asking about possible paths for a phone's lock screen pattern? Sep 14, 2017 at 19:53
• Do you know that this has a "nice" answer, or can be made significantly easier with some sort of "clever" insight? If not, then it's not appropriate for this site, and is likely to be closed.
– Deusovi
Sep 14, 2017 at 20:04
• I eradicated the sceptical part of question. Sep 14, 2017 at 20:23
• I think it's worth noting that you can't for instance go from (1,1) to (1,3) without hitting (1,2). Which i think make this incredibly hard to answer Sep 14, 2017 at 20:42

For the sake of brevity, I'm going to ignore the cases that @Andrey mentioned where going from dot 1 to dot 3 uses dot 2. (Also because it's not specifically listed as a rule in the original question. If anyone smarter than me knows how to make a formula that covers these instances, go for it.)

So if my maths is correct (which I wouldn't be surprised if it isn't), then the following formulas show how many patterns are available with each amount of dots used:

1 dot - This one's obvious, it's 9.
2 dots - With each dot, there are 8 other dots to go to, so it's 9*8=72
3 dots - Continuing with the previous logic, we get 9*8*7=504
4 dots - 9*8*7*6=3024
5 dots - 9*8*7*6*5=15120
6 dots - 9*8*7*6*5*4=60480
7 dots - 9*8*7*6*5*4*3=181440
8 dots - 9*8*7*6*5*4*3*2=362880
9 dots - Just to break the pattern here, as there's only 1 extra dot that can be added, we just double the amount of possible combinations from 8 dots, which is 362880*2=725760

Which when totalled, gives us

1349289 total possible combinations. Your phone is safe.

Assuming you cannot jump over a dot and according to the maths section: https://math.stackexchange.com/questions/37167/combination-of-smartphones-pattern-password

There is a total combination of:

389,112 possibilities.

However, this is counted 4 to 9 and OP wanted to know 1 to 9, thus the answer is:

389,497

Unless @Alpha mentions, you can't go in every single direction as (s)he says. Starting at two dots, you can't multiply it times 8, as you might jump over dots. Correct answer here should be:

2. - 56.

If we continue:

3, 320
4, 1624
5, 7152
6, 26016
7, 72912
8, 140704
9, 140704

Sum of all and a single 9 is the final answer.