Counter game

  • + 1 comment

    C# O(1) one-liner:

    public static string counterGame(long n)
    {
        return (long.PopCount(n) + long.TrailingZeroCount(n)) % 2 == 0 ? "Louise" : "Richard";
    }
    

    Makes use of POPCNT and TZCNT instructions, both O(1) on x86.