Binary permutations

Hello to everybody. I am an old research student in management and it has been 15 years since I last did any programming (it was in high school). Needless to say, it is taking me forever to learn C++, so I was wondering if somebody could kindly help me out.

I need a code (that will work in Dev-C++) that does the following:
1) user enters an integer N
2) computer generates a matrix 2^N (rows) by N (columns) such that rows only consist of 0 and 1 (of course all rows are different, i.e. orthogonal)

The algorithm I have in mind is as follows:
1) run a loop for "i" from 1 to N (or from 0 to N-1)
2) for every given "i" run a loop for "j" that goes from 1 to 2^(N-i)
3) for every given "j" run a loop for "k" that goes from 1 to 2^(i-1)
4) for every given "k" assign k consequtive zeros and k consequtive ones in the column (until the column is filled)

The output should like this:

0 0 0 0 0 0 ...
1 0 0 0 0 0 ...
0 1 0 0 0 0 ...
1 1 1 0 0 0 ...
0 0 1 1 0 0 ...
1 0 1 1 1 0 ...
0 1 0 1 1 1 ...
1 1 0 1 1 1 ...
0 0 0 0 1 1 ...
1 0 1 0 1 1 ...
...


Notice that the first column goes "01010101...", the second one goes "00110011...", the third one "000111000111...", etc. The final N-th column will have only zeros in the upper half followed by only ones in its lower half.

Thanx in advance.
Here is the weird utput that I am getting from my code:
http://img63.imageshack.us/img63/7905/cplusplus.jpg
nobody?
It seems like you already solved your problem.

You have your algorithm already.
Not sure if you are barking up the wrong tree. Is the output in your original post part of the specification? Normally permuting all the binary values would look something like:

000001
000010
000011
000100
000101
000110
000101
000111
001000
001001
....

Which is much easier to do...
Topic archived. No new replies allowed.