Write a binary counter in quine Write two code fragments, which we will call s_zero and s_one.

Program (l, n) consists of l copies of s_zero and s_one corresponding with the digits of n in binary, padded with s_zero on the left.

For example, if s_zero = foo and s_one = bar then
Program (4, 0) = foofoofoofoo
Program (4, 1) = foofoofoobar
Program (4, 2) = foofoobarfoo
etc.

Program (l, n) must print the source of Program (l, (n + 1) mod (2^l)) to standard out. In the example above, foobarfoofoo must print foobarfoobar when executed.

Your score is the sum of the lengths of fragments s_zero and s_one
CJam, 29 + 29 = 58 bytes

The 0 code:

0{"_~"]]z(3\+2b(2b2&gt;a\+z~[}_~


The 1 code:

1{"_~"]]z(3\+2b(2b2&gt;a\+z~[}_~


Explanation

0                       " Push the current bit. ";
{"_~"                   " The basic quine structure. ";
    ]                   " Make an array of the current bit, the function and _~.
                          That is the code fragment itself. ";
    ]                   " Make an array of all code fragments in the stack. ";
    z(                  " Extract the array of the bits. ";
    3\+2b(2b2&gt;          " Convert from base 2, decrease by one and convert back,
                          keeping the length. ";
    a\+z                " Put the bits back to the original position. ";
    ~                   " Dump the array of code fragments back into the stack. ";
    [                   " Mark the beginning position of the array of the next code fragment. ";
}_~