2
$\begingroup$

This is the problem : repeatedly add all its digits until the result has only one digit.

given the arbitrary number : 96491

This is the first solution that is pretty straight forward and I can understand. The result is $2$.

$(9+6+4+9+1 = 29) => (2+9 = 11) => (1+1 = 2) => 2$

Now here is another solution that I don't understand why it works.

$(9649 + 1 = 9650) => (965 + 0 => 965) => (96 + 5 = 101) => (10+1 = 11) => (1 +1 = 2) => 2$

What just happened? as you see the steps and results during steps seems completely different. yet they always produce same result. this number was just example. it works for any given positive number (tested with program for millions of different numbers). I'm really curios why second solution works? Thanks for explanations.

$\endgroup$
  • $\begingroup$ haha downvote xD , I know it may be stupid. but I'm really noob at math! thanks :) $\endgroup$ – M.kazem Akhgary Jan 14 '17 at 10:43
  • 2
    $\begingroup$ In terms of common computing operations, what you get if you repeatedly add the digits of a positive integer $n$ until you have a single digit left will always be (n - 1)%9 + 1, no matter what order you do it in. $\endgroup$ – Arthur Jan 14 '17 at 10:52
2
$\begingroup$

Arthur already pointed out the main reason, but I want to clarify it a bit :

The remainder modulo $9$ does not change if we replace any number by the sum of its digits, this can be easily seen : If we have $$N=a_k\cdot 10^k+a_{k-1}\cdot 10^{k-1}+\cdots+a_1\cdot 10+a_0$$ then we have $$N\equiv a_k+a_{k-1}+\cdots +a_1+a_0\mod 9$$ because of $$10^n\equiv 1\mod 9$$ for every non-negative integer $n$.

The final result is $N\mod 9$ , if $N$ is not divisible by $9$ and $9$ , if $N$ is divisble by $9$. As Arthur pointed out, the formula $$((N-1)\mod 9)+1$$ covers all cases.

$\endgroup$
  • $\begingroup$ oh is that modular arithmetic? must go back to school :) interesting thanks. $\endgroup$ – M.kazem Akhgary Jan 14 '17 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.