Recursive Digit Sum

  • + 0 comments

    There is a faster method creating a new recursive function that only works with numbers instead of string, but not sure if that was asked, because of how the question was structured.

    Also, you can not even use recursion and just take (n*k)%9, but seems kinda magic

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def superDigit(n, k):
        if (len(n) == 1) and (k == 1):
            return int(n)
    
        sum = 0
        for number in n:
            sum += int(number)
        return superDigit(str(sum * k), 1)