Determine the total number of sevendigit base 10 positive integers divisible by 11 and having the sum of their digits equal to 59. (No computer programs)
(In reply to
No Subject by Ady TZIDON)
Since a verification program is to test assumptions (i.e., wellknown facts) made in the solution, it would pay to make the test as assumptionfree as possible. Here we start with the lowest 7digit number whose digits add to 59 and proceed until 9999999 is exceeded.
DECLARE FUNCTION digsum# (x#)
DECLARE FUNCTION digroot# (x#)
DEFDBL AZ
CLS
n = 5999999
mod11 = n MOD 11
n = n + 11  mod11
dr = digroot(n)
DO
IF dr = 5 THEN
IF digsum(n) = 59 THEN
PRINT n: ct = ct + 1
END IF
END IF
n = n + 11
dr = dr + 2: IF dr > 9 THEN dr = dr  9
LOOP UNTIL n > 9999999
PRINT ct
FUNCTION digroot (x)
s = x
DO
s = digsum(s)
LOOP UNTIL s < 10
digroot = s
END FUNCTION
FUNCTION digsum (x)
s$ = LTRIM$(STR$(x))
FOR i = 1 TO LEN(s$)
t = t + VAL(MID$(s$, i, 1))
NEXT
digsum = t
END FUNCTION
resulting in:
8699999
8798999
8799989
8897999
8898989
8899979
8996999
8997989
8998979
8999969
9689999
9699899
9699998
9788999
9789989
9798899
9798998
9799889
9799988
9887999
9888989
9889979
9897899
9897998
9898889
9898988
9899879
9899978
9986999
9987989
9988979
9989969
9996899
9996998
9997889
9997988
9998879
9998978
9999869
9999968
40
showing the count is indeed 40.

Posted by Charlie
on 20130607 13:38:53 