I am looking for an algorithm that can create numbers following certain patterns. Let’s say I have a binary number of size n and the patterns I would like to create is having 0s and 1s in equal numbers such that they are repeated with different spacings. The pattern of repetition and spacing will be clear from the example below:

If size is 4, set of numbers are: {0101, 0011}.

If size is 8, set of numbers are: {01010101, 00110011, 00001111}.

If size is 16, set of numbers are: {“01”*(8), “0011”*(4), “00001111”*(2)}.
If size is n, set of numbers are: {“01”*(2^n-1), “0011”

*(2^n-2), “00001111”*(2^n-3), …}

Note: Sorry for the bad notation!

For this problem, n will always be an integer power of 2 (e.g. 2, 4, 8, 16, 32 …). So the size of set will always be $log_2$(n). Is there an algorithm that can generate each of these numbers in the set with algorithm in the range of O(1) to O(n)?

Thanks.