Find out the final survivor

677 Views Asked by At

A question one of my friend asked me:

There are $n$ (he told me to find for $100$ people and then asked the general formula for $n$ people) people sitting at a round table. A person (say $1$) killed $2$ and passed the gun to $3$. $3$ killed $4$ and passed the gun to $5$....
also, after reaching $99$ or so the cycle would again continue, someone will kill $1$ and pass the gun to $3$.

Who is the last one to remain alive?

Any help would be appreciated. :)
Also, I'm unable to find a proper tag for this question.

2

There are 2 best solutions below

0
On BEST ANSWER

Determine the survivor by letting a program find the solution gives me this: $$n -> survivor \\ 3 -> 3\\ 4 -> 1\\ 5 -> 3\\ 6 -> 5\\ 7 -> 7\\ 8 -> 1\\ 9 -> 3\\ 10 -> 5\\ 11 -> 7\\ 12 -> 9\\ 13 -> 11\\ 14 -> 13\\ 15 -> 15\\ 16 -> 1\\ 17 -> 3\\ 18 -> 5\\ ... \\ 30 -> 29\\ 31 -> 31\\ 32 -> 1\\ 33 -> 3\\ ... \\ 62 -> 61\\ 63 -> 63\\ 64 -> 1\\ 65 -> 3\\ ... \\ 126 -> 125\\ 127 -> 127\\ 128 -> 1\\ 129 -> 3\\ ... \\ 254 -> 253\\ 255 -> 255\\ 256 -> 1\\ 257 -> 3\\ $$ and so on. If $n = 1$ gets the gun first. Oh and by $n=100$ it's $73$ who survives.

1
On

There is a very reliable and easy method to compute the answer.

Total no of participants=N

Now, convert N into its binary value, remove the first digit of this value and append it at its end. Now convert this binary value to its decimal equivalent, That is your answer

eg:1) N=100, Binary value of N=1100100 now remove the first digit:1 and append it at the end: giving binary number: 1001001, convert it back to decimal: giving your answer 73

2) N=41(Asked to Josephus originally), bin(41)=101001, now answer=010011 whose decimal equivalent is:19

3)N=126, bin(N)=1111110 , bin(answer)=1111101 , answer=125

Hope this helps