FastCode Challenge: Longevity

Run-length encoding is a trivial compression mechanism. It replaces a count of repeated data with a value-count pair. In the special case of encoding binary data, the value can be omitted since the values must alternate. For example, the run-length encoding for the binary number 1110000101100 is the sequence (3, 4, 1, 1, 2, 2).

By concatenating the binary value of each number in the sequence we obtain a new binary number: 11 100 1 1 10 10, which could, in turn, be similarly encoded.

The longevity of a number is the number of times a binary number can be run-length encoded and concatenated before the length of the bit sequence is reduced to two. For example, the longevity of 1110000101100 is eleven, as shown below.

1110000101100
  11100111010
    111011111
       111101
        10011
        11010
        10111
         1111
          100
          110
          101
          111
           11

Write a program to compute the longevity of a binary number.

Input

Each dataset is a single binary number represented as a little endian integer. For example, the following shows the output from hexdump of input.bin, which contains the example number above.

$ hexdump -e '16/1 "%02x " "\n"' input.bin
2c 1c

The file described above contains the hexadecimal number 0x1c2c, whose binary representation is 0001 1100 0010 1100. The first encoding sequence is (3, 4, 1, 1, 2, 2) as described above. (Ignore leading zeros on input.)

Output

Your program should compute the longevity of the number provided as described above. For example, the above input should produce the following.

{
    "answer" : 11
}