Binary grid pemutations

58 Views Asked by At

Lets say you have a binary number with n amount of digits, 4 for example, I know I could get all the permutations by simply using the formula 2^n. This gives 16 unique combinations so I could simply take the numbers 1-16 and convert it to binary: {0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 0000}

1: How do I filter out mirror matches like (0001,1000) or (1010,0101) where the number is just flipped.

2: Similarly, cases where the number is just shifted left or right (0001,0010,0100,1000) or (0011,0110,1100).

3:Do the same as above on a grid of x,y size adding another dimension for example:
arrays represented as grid

In the first example the arrays can be represented as follows but they need to be filtered out as they are the same "object". The second example shows a similar case but the "object" is not actually attached to itself.

example 1:

original: {0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1}
x-1,y-1: {0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0}
flipped y axis: {0,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0}
flipped x axis: {0,0,0,0,0,1,0,0,0,1,0,0,1,1,0,0}

example 2

original: {0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0}
x-1,y-1: {1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0}
flipped y axis: {0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0}
flipped x axis: {0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0}