I have a set of numbers from $0$ to $2^7$. I need to arrange these numbers in a matrix where each number is surrounded by a different arrangement of numbers. So basically, I need to obtain as many permutations as I can for each number with respect to the adjacent elements which of which I am using $4$ (out of the $8$ that surround each number). But, I also need all of these numbers to form 1 matrix, which might be the difficult part here.
Is this possible? How can I calculate the number of permutations that I can obtain for each number?