What is the algorithm for this?

if I have a string 000111 (or any amount of zeros and ones), what is the algorithm for me to get all possible combinations? (001011, 001101, ...)

Odd but the following code does not yeild the results you list in your post. Maybe you have a mistake? Or am I missing something?
class test
public int[] getC(int[] c, int n)
          int m= c.length;
          for (int i= m; i-- > 0;)
               if (++c[i] <= n-(m-i))
                    while (++i < m)
                         c= c[i-1]+1;
                    return c;
          return null;
     public static void main(String[] args)
          test t = new test();
          int[] input = {0,1};
          int n = 4;
          int[] res = t.getC(input, n);
          for (int i = 0; i < res.length; i++)
               System.out.println(res[i]);

Similar Messages

Maybe you are looking for