Recursive Digit Sum

  • + 1 comment

    C# Solution

    (looks like no test cases start with n == 1 and k > 1)

    ''' public static int superDigit(string n, int k) { if (n.Length == 1) return Convert.ToInt32(n);

        var sum = 0L;
        n.ToList().ForEach(c => sum += Convert.ToInt64(Char.GetNumericValue(c)));
        if (k > 1) sum += sum * (k - 1);
        return superDigit(Convert.ToString(sum), 1);
    }
    

    } '''