You are viewing a single comment's thread. Return to all comments →
think about it this way.
Convert the number to binary format.
1010 -> (010 - 10 ) -> 10
If a number at any given point of time is a power of 2, then it will be of the form
10000(xtimes)
Then, remove the right most 0 from the binary representation of the number
0
else
remove the left most 1 and also remove any left most 0s till you find a 1.
1
Example:-
1010
this is not a power of 2 ( why? ), so this number gets reduced to 010 = 10 ( 2 in decimal )
2
010
10
this is a power of 2.
so, I remove the right most 0 and the game ends.
Seems like cookies are disabled on this browser, please enable them to open this website
Counter game
You are viewing a single comment's thread. Return to all comments →
think about it this way.
Convert the number to binary format.
If a number at any given point of time is a power of 2, then it will be of the form
Then, remove the right most
0
from the binary representation of the numberelse
remove the left most 1 and also remove any left most
0
s till you find a1
.Example:-
this is not a power of
2
( why? ), so this number gets reduced to010
=10
( 2 in decimal )this is a power of
2
.so, I remove the right most
0
and the game ends.