Let there be "N" bits.
We want to rank and unrank a specific subset of bit combinations based on the following criteria -
The number of consecutive 0s must be minimum "k" or more (k<N).
How can we rank (and unrank) only based on the given bit combination (and not by iterating the full range of 2^N bits). This will be efficient for large N bits.
I tried the following approach (example with N=5 and k=3) -
Start from LSB bit (position 1), and count the number of possible combinations with >=3 consecutive 0s:
Position 1 - 0 >=3 consecutive 0s
Position 2 - 0 >=3 consecutive 0s
Position 3 - 1 >=3 consecutive 0s
Position 4 - 3 >=3 consecutive 0s
Position 5 - 8 >=3 consecutive 0s
How can this information be used, along with bit-shifting patterns, to do the rank and unrank of a given bit combination.
This is another question where the ranking is based on "<=2" consecutive 0s; however what I now want is the opposite case, i.e. >=3 consecutive 0s.
Example -
N: 5 bits
k: >=3 consecutive 0s
00000 - k>=3 - rank - 00001 - unrank - 00000
00001 - k>=3 - rank - 00010 - unrank - 00001
00010 - k>=3 - rank - 00011 - unrank - 00010
00011 - k>=3 - rank - 00100 - unrank - 00011
00100
00101
00110
00111
01000 - k>=3 - rank - 00101 - unrank - 01000
01001
01010
01011
01100
01101
01110
01111
10000 - k>=3 - rank - 00110 - unrank - 10000
10001 - k>=3 - rank - 00111 - unrank - 10001
10010
10011
10100
10101
10110
10111
11000 - k>=3 - rank - 01000 - unrank - 11000
11001
11010
11011
11100
11101
11110
11111
Thanks!