Solved

# Binary matrix for all possible unique results of X(i) variables

Posted on 2008-02-11

How to generate a binary matrix for all possible permutations of 'i' variables X, where " i " can be any number between 1 and infinite. I know that the resultant matrix will have 2^ i unique answers, but don't know how to generate it. Let me explain by example:

variables x1, x2 (i=2) each with a possible value of 1 or 0, so the resultant matrx would be:

X2 X1

0 0

0 1

1 0

1 1

but what if i=120 for example, how do we generate the matrix for x(i) from 1 to 120? There would be 2^ 120 results.

The logic is simple, but I can not seem to translate to code:

x4 x3 x2 x1

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

generate matrix 2^i by i size

start with all x(i) values at 0

get value of x(i)

if x(i)=1

increment i

else set x(i)=1 then start checking values from beginning

if i reaches count of total variables for that row OR leftmost variable is 1 move to next row

or something like above