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.
First consider case where the input is only one digit:
superdigit(x where x<10)
its obvious that superdigit(x) =x mod 9 if x is smaller than 9. Only x==9 will be an edge case.
Now we consider a decimal number such as 100*a+10*b+c and we can prove that
100*a+10*b+c mod 9 =(a+b+c) mod 9 +(99*a+9*b)mod 9
100*a+10*b+c mod 9=0+(a+b+c) mod 9 which means mod9 conserves through recursive superdigit operation.
Then if we have any given input a, we can draw a chain like a-b-c-..-x
where x is a single digit number.
From the previous paragraph, we know that amod9==bmod9==cmod9 .... ==xmod9
From the property defined in superdigit operation, we know that
supdigit(a)==superdigit(b)==superdigit(c)==...superdigit(x)
Since in the first pragraph, we showed that superdigit(x)==xmod9 despite the edge case where x==9. This tells us that tails of two chains are equal, so the heads of two chains must also be equal except x==9 case.
Therefore supdigit(a)==a mod 9 if a mod 9!=0
supdigit(a)==9 if a mod9 ==0
which
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 →
First consider case where the input is only one digit: superdigit(x where x<10)
its obvious that superdigit(x) =x mod 9 if x is smaller than 9. Only x==9 will be an edge case. Now we consider a decimal number such as 100*a+10*b+c and we can prove that 100*a+10*b+c mod 9 =(a+b+c) mod 9 +(99*a+9*b)mod 9 100*a+10*b+c mod 9=0+(a+b+c) mod 9 which means mod9 conserves through recursive superdigit operation.
Then if we have any given input a, we can draw a chain like a-b-c-..-x where x is a single digit number.
From the previous paragraph, we know that amod9==bmod9==cmod9 .... ==xmod9
From the property defined in superdigit operation, we know that supdigit(a)==superdigit(b)==superdigit(c)==...superdigit(x)
Since in the first pragraph, we showed that superdigit(x)==xmod9 despite the edge case where x==9. This tells us that tails of two chains are equal, so the heads of two chains must also be equal except x==9 case.
Therefore supdigit(a)==a mod 9 if a mod 9!=0 supdigit(a)==9 if a mod9 ==0
which