Page 1 of 1

Permutations of binary variable

Posted: Wed May 01, 2013 9:36 am
by fboehlandt
Hi,
I am looking for a way to create permutations of a binary variable for different n. Assuming n=3:

0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1
1 0 1
1 1 1

Does anybody have a code snippet that could be of use?
Many thanks in advance

Re: Permutations of binary variable

Posted: Fri May 03, 2013 3:50 am
by fboehlandt
I have come up with this quickshot solution. Should work for other permutations as well with a little adaptation. Only drawback is that the permutations may not be in the desired order. Worked for my purposes though

Code: Select all

!nvar = 4 table(!nvar^2,!nvar) testtable !bin = 1 !s = !nvar ^ 2 for !j = 1 to !nvar !s = !s / 2 for !i = 1 to !nvar ^ 2 if (!i - 1) / !s = @round((!i - 1) / !s) Then !bin = @abs(1 - !bin) testtable(!i, !j) = !bin else testtable(!i, !j) = !bin endif next next