We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Recursive Digit Sum
- Discussions
Recursive Digit Sum
Recursive Digit Sum
Sort by
recency
|
591 Discussions
|
Please Login in order to post a comment
go is unfortunately pretty badly supported here.
My code produces a Runtime Error just for test cases 7,8,9, while the exact same code produces correct output on my machine (for case 7:the expected 7).
It's also suspicious that a Runtime Error happens only for a certain case...usually it's a real problem or not. :(( hackerrank these are things wanting to move me away to other platforms.
def superDigit(n, k): str1 = str(n) sum1 = 0 for char in str1: sum1 += int(char) sum1 = k*sum1 while True: str2 = str(sum1) sum1 = 0 for char in str2: sum1 += int(char) if sum1 < 10: break return sum1
Java 8 solution. Passed all cases. Make sure you are storing the sum of the digits as a Long.
I guess test cases 0, 10 and 11 are not well designed, since they expect an output of 3 for an input of 148, an output of 8 for an input of 875, and an output of 9 for an input of 123. I am working with Swift.
php solution: