Post Reply 
(11C) Sum of All Digits
11-17-2018, 04:56 PM (This post was last modified: 11-17-2018 05:56 PM by Dieter.)
Post: #4
RE: (11C) Sum of All Digits
(11-17-2018 02:26 PM)Albert Chan Wrote:  Using LOG to scale away exponents assumed number > 0

May I ask why the number is scaled at all?
Is a simple mod 9 not sufficient?

Also scaling by means of the base 10 log can be problematic. Try 999999999, the log of this is returned as exactly 9. And this is just a nine-digit number. Among the 10-digit numbers even log 9999999989 is calculated as exactly 10. So the scaling goes wrong. But I think it is not required anyway. Or is it? Gamo?

(11-17-2018 02:26 PM)Albert Chan Wrote:  So, mod 9 of scaled number can be simplified a bit

9 / FRAC 10 x INT

This would mean a program like this:

Code:
LBL A
9
÷
FRAC
1
0
x
INT
X=0?
9
RTN

Thomas said the max. input is 9 E+9, but actually the limit is even lower due to roundoff: try 8765432123. Dividing this by 9 yields 973936902,5555... so that the result should be 5. But with 10-digit accuracy this is rounded to 973936902,6 so the program returns 6 instead.

On the other hand the classic mod 9 implementation requires just one more step. It doesn't have the mentioned problem and it works for input up to 9 E+9.

Code:
LBL A
ENTER
ENTER
9
÷
INT
9
x
-
X=0?
9
RTN

8765432123  [A]  =>  5

BTW, unlike the original program this method also works on the 12C.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) Sum of All Digits - Gamo - 11-17-2018, 08:22 AM
RE: (11C) Sum of All Digits - Albert Chan - 11-17-2018, 02:26 PM
RE: (11C) Sum of All Digits - Dieter - 11-17-2018 04:56 PM
RE: (11C) Sum of All Digits - Albert Chan - 11-17-2018, 06:27 PM
RE: (11C) Sum of All Digits - Thomas Klemm - 11-17-2018, 02:51 PM



User(s) browsing this thread: 1 Guest(s)