### Josephus Problem - Puzzle

Read about this in Concrete Mathematics - Knuth some time back... Interesting problem There are n persons in a circle, numbered 1 to n. Going around the circle, every second person is removed from the circle, starting with person number 2, 4, and so on. Show that the number of the last person remaining in the circle can be obtained by writing n in binary, then moving the leftmost 1 to the right. So for example, with n = 13 persons (1101 in binary), the last person is number 11 (1011 in binary). Math at : http://en.wikipedia.org/wiki/Josephus_problem Solution: In case of 13, The order in which people die are xxx0 xx01 {Since last bit of 13 was 1, hence xx01, otherwise it would have been xx11} x111 {Since secondlast bit of 13 was 0, hence x111, otherwise it would have been x011} 0011 {Since thirdlast bit ....} So, you would want to be 1011 So, we can see that the solution for a general n is in the bit representation of n, add a bit 1 at the end and remove the first bi