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.
publicstaticstringcounterGame(longn){longstarting=n;stringbinary;for(inti=1;i<Convert.ToString(starting,2).Length;i++){//Converts n to binary respresentationbinary=Convert.ToString(n,2);//Checks for if it is a power of 2 by checking for 1's besides leading bitif(binary[1..].Contains('1')){n-=(long)Math.Pow(2,binary.Length-1);//If so, minus leading bit's decimal}else{n/=2;//Is power of 2, so divide by 2.}//Even numbered moves Richard wins, otherwise Louise wins.if(n==1)returni%2==0?"Richard":"Louise";}//If n is 1, Richard automatically wins.return"Richard";}
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 →
C#