Advertisement
Kali_prasad

louis and richard game

Mar 11th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. string counterGame(long n) {
  2. long count=0;
  3.   while(n)
  4.  {
  5.     long bits=0;
  6.     long ones=0;
  7.     long temp=n;
  8.     while(temp)
  9.     {
  10.         if(temp%2!=0)
  11.         ones++;
  12.         bits++;
  13.         temp>>=1;
  14.        
  15.     }
  16.     bits=bits-1;
  17.     if(ones==1)
  18.     {
  19.         n/=2;
  20.     }
  21.     else
  22.     {
  23.         n-=(1<<bits);
  24.     }
  25.    
  26.  
  27.     count++;
  28.     if(n==1)
  29.     break;
  30. }
  31. if(count%2!=0)
  32. return "Louise";
  33. else
  34. return "Richard";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement