I want to find all possible binary permutations with a given number of ones in Java:
- x is the desired number of ones in each sequence
- n is the desired length of each sequence
For an example:
x=2
, n=4
Output: 1100, 0011, 1010, 1001, 0101, 0110
I'm searching for an elegant and fast way to do this. Can you help me?
I've tested eboix solution in Print list of binary permutations but it is unfortunately too slow because the algorithm in this example is searching for all 2^n
binary permutations.
I want to find sequences with a length of 50
or 100
.