(11C) Digit Sum
|
01-16-2018, 07:16 PM
Post: #2
|
|||
|
|||
RE: (11C) Digit Sum
Gamo, this is one of your best-coded programs. And it uses a clever algorithm: it sums 1/10 of the digits and finally multiplies the result by 10. Which is obtained by two consecutive 10x commands (0 → 1 → 10).
I like such little tricks (altough a plain 10 is faster and doesn't require more steps). Let me add one more: If you want to zero data register 1 without affecting the stack, a simple STO 1 STO–1 does it. Saves one step here. By the way... (01-16-2018 08:52 AM)Gamo Wrote: In mathematics, the digit sum of a given integer is the sum of all its digits And the digit sum of this (the digital root) is 4 (simply run the program once more). But you can calculate this directly, it's simply n mod 9. Or 9 if this yields zero (and n≠0). Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(11C) Digit Sum - Gamo - 01-16-2018, 08:52 AM
RE: (11C) Digit Sum - Dieter - 01-16-2018 07:16 PM
RE: (11C) Digit Sum - wawa - 01-20-2018, 08:14 AM
RE: (11C) Digit Sum - Dieter - 01-20-2018, 09:23 AM
RE: (11C) Digit Sum - Gamo - 01-20-2018, 10:10 AM
RE: (11C) Digit Sum - Dieter - 01-20-2018, 05:21 PM
|
User(s) browsing this thread: 1 Guest(s)