C#C
C#15mo ago
KevToTo

Need help

    public static string CaesarTower(int n)
    {
        if (n < 1)
        {
            throw new ArgumentException();
        }
        int to;
        
        string res = $"Moves for {n} disks\n";
        int total = (int)Basix.MyPow(2, n) - 1;
        for (int i = 1; i <= total ; i++)
        {
            if (n%2==1)
            {
                res += (i & i - 1) % 3 + 1 + " -> " + (((i | i - 1) + 1) % 3                 + 1);
            }
            else
            {
              ...
            }
            if (i != total)
                res += "\n";
        }

        return res;



My program works for all odd numbers, but I don't know how to make it work for all numbers
Was this page helpful?