I have an interesting bitmask puzzle problem I need help solving in something. Here is the problem:
11010
Each bit represents a characteristic of a piece of content. It is stored in Redis. But to query it, we need every combination so that we can pull up the key. So 11010 would yield these combinations:
11010
10000
10010
11000
01010
00010
01000
Anyone have a solution in C++?
See the Chess Programming Wiki for an algorithm that is linear in the number of subsets of the initial bitmask. With n bits set to 1, that number is equal to 2^n, so it’s exponential in the number of set bits.