Explanation of the binary shift method for Josephus Problem

imported
uncategorized
Published

October 25, 2013

“The most elegant form of the answer involves the binary representation of size n: f(n) can be obtained by a one-bit left cyclic shift of n itself.” Link: http://en.wikipedia.org/wiki/Josephus_problem Let n be a binary number as \[n=1b_1b_2b_3...b_m\], then the solution is given by \[f(n)=b_1b_2b_3...b_m1\] \[ 2^{\lfloor \log 2^n \rfloor}=10000...0 \](m number of 0s) \[n-2^{\lfloor \log 2^n \rfloor}=b_1b_2b_3...b_m\] \[ 2*(n-2^{\lfloor \log 2^n \rfloor})=b_1b_2b_3...b_m0\] \[ 2*(n-2^{\lfloor \log 2^n \rfloor})+1=b_1b_2b_3...b_m1\]