I'm looking for a math function that taking an integer returns the sum of it's digits. I tried with this method:
-I've got a digit sequence $d_{k+1},d_{k},...,d_{1}$ with $d_{k+1}\ne 0$ and $d_i \in \{0,1,2 \dots , 9\}$ for all $1 \le i \le k+1$; this represents the number $A$ in base $10$, so: $$A = \sum_{i = 1}^{k+1} d_i 10^{i-1}$$
-Now I know that each digit is generated by: $$d_i = \sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\frac{A\,\, \pmod{10^i}-A\,\, \pmod{10^{i-1}} }{10^{i-1}}$$
-I expand the sum and I obtain: $$\frac{A\, \pmod{10}-A\,\, \pmod1}{1}+\frac{A\, \pmod{10^2}-A\,\, \pmod{10}}{10}+\cdots +\frac{A\, \pmod{ 10^i}-A\pmod{10^{i-1}}}{10^{i-1}}$$
-I have to simplify the denominator so: $$\frac{1\cdot (A\, \pmod{10}-A\,\, \pmod1)}{1}+\frac{10\cdot (\lfloor\frac{A}{10}\rfloor\, \pmod{10}-\lfloor\frac{A}{10}\rfloor\,\, \pmod 1)}{10}+\cdots +\frac{10^{i-1}\cdot (\lfloor{\frac{A}{10^{i-1}}}\rfloor\, \pmod{10}-\lfloor\frac{A}{10^{i-1}}\rfloor\,\, \pmod 1)}{10^{i-1}}$$
-I split the term: $$A\, \, \pmod{10}+\lfloor\frac{A}{10}\rfloor\, \, \pmod{10}+\cdots+\lfloor\frac{A}{10^{i-1}}\rfloor\, \, \pmod{10}-(A\, \, \pmod1+\lfloor\frac{A}{10}\rfloor\, \, \pmod1+\cdots +\lfloor\frac{A}{10^{i-1}}\rfloor\, \, \pmod1)$$
-Now I would have picked up $\pmod{10}$ and $\pmod1$: $$\left (\sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\lfloor\frac{A}{10^{i-1}}\rfloor\right)\, \, \pmod{10}-\left (\sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\lfloor\frac{A}{10^{i-1}}\rfloor\right)\, \, \pmod1$$; but I can't. Any ideas to move forward?
Thanks