Ad
  • Custom User Avatar

    Which language? Which test, and what's the input parameter (print it)? Please provide more insight before marking as an issue.

  • Custom User Avatar

    In the Java testcases, the expected and the actual are swapped around, so your solution is returning 15 and the expected answer is 6.

  • Custom User Avatar

    Instructions are very clear.
    The description states:

    A digital root is the recursive sum of all the digits in a number.

    recusive = characterized by recurrence or repetition

    This implies your code has to keep repeating. Unless you're fucking retarded you should know the sum of digits of a single digit is the digit itself and therefore your code should stop.

    This description also provides valid examples, for example:

    digital_root(493193)

    => 4 + 9 + 3 + 1 + 9 + 3

    => 29 ...

    => 2 + 9

    => 11 ...

    => 1 + 1

    => 2

  • Custom User Avatar

    Read the comments next time you think you encounter an issue.

    Your code only calculates the sum of digits once, but you need to keep summing the digits of the new number if the number is less than 10. Read the description, it states that the function is recursive, so you have to keep doing it until there is only one digit. The input value is 195, the expected value is 6 and your code returns 15.

    n = 195
    
    1 + 9 + 5 = 15
    1 + 5 = 6
    
  • Custom User Avatar

    Read the comments next time you think you encounter an issue.

    Your code only calculates the sum of digits once, but you need to keep summing the digits of the new number if the number is less than 10. Read the description, it states that the function is recursive, so you have to keep doing it until there is only one digit. The input value is 195, the expected value is 6 and your code returns 15.

    n = 195
    
    1 + 9 + 5 = 15
    1 + 5 = 6
    
  • Custom User Avatar

    Happy to be told that I am wrong, but this did not work for me:

    n.to_s.split("").inject(0) { |res, num| res += num.to_i }

    I think jriches is right, there might be a problem with the tests.