We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Now, Lousie goes first. As 1010 is not a power of 2, it is reduced by the largest power of 2 less than 1010 which is 8. Now, the counter is 2. As 2 is a power of 2, it is reduced by half by Richard to 1 and the game ends.
Richard Wins.
Your code however prints Louise as the winner.
Cookie support is required to access HackerRank
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 →
Oh man
let's look at the following input
this when represented in Binary is
1010
Now,
Lousie
goes first. As1010
is not a power of 2, it is reduced by the largest power of 2 less than1010
which is8
. Now, the counter is2
. As2
is a power of2
, it is reduced by half byRichard
to1
and the game ends.Richard
Wins.Your code however prints
Louise
as the winner.