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.
Python solution. Another terrible formulated problem, look at the line:
n = str(sum(int(digit) for digit in n))k
This is not what the problem asks, but works, because when working with big numbers you cannot simply multiply the string, here throws a Memory Error, you need to reduce first, something you wouldn't do if was a normal work, you NEED the exception that was throw to investigate, that is how a developer work, ffs!
Also who knows the math that multiply the sum of digits is the same of sum the multiply of the original number?
Where are those genius?
defsuperDigit(n,k):# Apply k at the beginningn=str(sum(int(digit)fordigitinn))*k# Reduce until single digitwhilelen(n)>1:n=str(sum(int(digit)fordigitinn))returnint(n)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Python solution. Another terrible formulated problem, look at the line:
n = str(sum(int(digit) for digit in n))k
This is not what the problem asks, but works, because when working with big numbers you cannot simply multiply the string, here throws a Memory Error, you need to reduce first, something you wouldn't do if was a normal work, you NEED the exception that was throw to investigate, that is how a developer work, ffs!
Also who knows the math that multiply the sum of digits is the same of sum the multiply of the original number?
Where are those genius?