Member • Dec 20, 2011

## Can you find an efficient solution to this bit manipulation problem?

For a length of 5,

Map (1,5) to 01110

Map (1,4) to 01100

Map (2,4) to 00100

and so on.

You can use any binary operators and the binary representations of given number limits (obviously).

I am trying to find an optimum solution with minimal looping and more intelligent use of binary operations. Can you try?!

**Update:**

*more explanation*

For a length of 5, consider a row like this:

- * - -*

(_ is empty space and * is occupied space)

Now, for the above row, the indices of occupied spaces are:

(2,5)

Suppose we're representing

- the empty spaces
*between**'s by 1's - all the rest by 0's (Note that 0's in the right side matter!)

*maps to*(2,5)

*maps to*00110

_ * * _ _

*maps to*(2,3)

*maps to*00000

I think that's clear now!