Fog Creek Software
Discussion Board




technical riddles (people inside & outside a room)

The constraint to "move one person in or out" suggests a similarity with Gray code. Assuming that each person is assigned a bit-position, and that the persons inside form a number which is the sum of their bit positions, we need to cycle through all combinations by toggling one bit each time.

Just follow the Gray code encoding and you're on your way!

Manas
Monday, November 04, 2002

*  Recent Topics

*  Fog Creek Home