All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 The Magnificent Eleven (Posted on 2012-07-07)
You are requested to perform 2 independent tasks:

a) Using ten distinct digits (0 to 9) plus an additional digit of your choice create the smallest 11-digit number, divisible by 495.
b) Using ten distinct digits (0 to 9) plus an additional digit of your choice create the biggest 11-digit number, divisible by 495.

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 2 of 3 |

Since 495 is 3*3*5*11, the number must be divisible by 9, 5 and 11.

As it's divisible by 9, the repeated digit must be either 0 or 9. As it's divisible by 5, the last digit must be 0 or 5. As it's divisible by 11, the difference between the sums of the odd and even position digits must be congruent to zero mod 11.

That's the basis for this program (except for the mod 11 part), run under QB64 which allows the MOD function to run on such large numbers.

DEFDBL A-Z
DECLARE SUB permute (a\$)
CLS
a\$ = "1023456789": h\$ = a\$
low = 99999999999
DO
n = VAL(a\$ + "0")
IF n MOD 495 = 0 AND n < low THEN low = n
IF n MOD 495 = 0 THEN high = n
permute a\$
LOOP UNTIL LEFT\$(a\$, 1) = "0"

a\$ = "1002346789": h\$ = a\$
DO
n = VAL(a\$ + "5")
IF n MOD 495 = 0 THEN
IF n < low THEN low = n
IF n > high THEN high = n
END IF
permute a\$
LOOP UNTIL LEFT\$(a\$, 1) = "0"

a\$ = "1234567899": h\$ = a\$
DO
n = VAL(a\$ + "0")
IF n MOD 495 = 0 AND n < low THEN low = n
IF n MOD 495 = 0 AND n > high THEN high = n
permute a\$
LOOP UNTIL a\$ = h\$

a\$ = "1023467899": h\$ = a\$
DO
n = VAL(a\$ + "5")
IF n MOD 495 = 0 THEN
IF n < low THEN low = n
IF n > high THEN high = n
END IF
permute a\$
LOOP UNTIL LEFT\$(a\$, 1) = "0"

PRINT low, high

The results are 10026374985 and 99876534120 respectively.

 Posted by Charlie on 2012-07-07 18:12:09

 Search: Search body:
Forums (0)