Post Reply 
(11C) Sum of All Digits
11-17-2018, 06:27 PM (This post was last modified: 11-17-2018 07:44 PM by Albert Chan.)
Post: #5
RE: (11C) Sum of All Digits
(11-17-2018 04:56 PM)Dieter Wrote:  May I ask why the number is scaled at all?
Is a simple mod 9 not sufficient?

I think Gamo is trying to cover all ranges (except 0, or negative numbers).
I am not sure LOG can guarantee correct scaling though.

Example, LOG(99999 99991) = 10 (rounded from exact = 9.9999 99999 60913 ...)
Scaling it by 1/10^(10-9), we get X = 99999 9999.1
X % 9 returns weird sum of digits = 0.1 ???

Edit: scaling can still work, sum of digits = (X + 9*frac(X)) % 9
The correction fix possible INT LOG off-by-1 error.

(11-17-2018 04:56 PM)Dieter Wrote:  Thomas said the max. input is 9 E+9, but the limit is even lower due to roundoff errors ...

"9 / FRAC 10 x INT" idea is bad ...
In fact, this start failing even for 9 digits integer >= 9e8 + 5

Your mod9 code can handle full 10 digits integer (and a hair more, to 1e10)
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)