(I) What is the largest 3-digit base ten positive integer such that when multiplied by a single digit, the result is a base ten 4-digit positive integer, with consecutive digits in order (example: 1234, 4567 etc, but not 0123 or, 7968)?
(II) What is the largest 3-digit base ten positive integer such that when multiplied by a single digit, the result is a base ten 4-digit positive integer, with consecutive digits in reverse order (example: 3210, 5432 etc, but not 9786)?
DEFDBL A-Z
CLS
FOR n = 100 TO 999
FOR mltplr = 2 TO 9
prod = n * mltplr
IF prod > 999 AND prod < 10000 THEN
p$ = LTRIM$(STR$(prod))
ascend = 1
FOR i = 1 TO 3
IF VAL(MID$(p$, i + 1, 1)) <> VAL(MID$(p$, i, 1)) + 1 THEN ascend = 0
NEXT
descend = 1
FOR i = 1 TO 3
IF VAL(MID$(p$, i + 1, 1)) <> VAL(MID$(p$, i, 1)) - 1 THEN descend = 0
NEXT
good = ascend OR descend
IF good THEN
PRINT n; "*"; mltplr; "="; prod;
IF ascend THEN PRINT TAB(20); "asc.";
IF descend THEN PRINT TAB(28); "desc.";
PRINT
END IF
END IF
NEXT mltplr
NEXT
finds
335 * 7 = 2345 asc.
384 * 9 = 3456 asc.
432 * 8 = 3456 asc.
469 * 5 = 2345 asc.
535 * 6 = 3210 desc.
576 * 6 = 3456 asc.
617 * 2 = 1234 asc.
642 * 5 = 3210 desc.
679 * 8 = 5432 desc.
727 * 9 = 6543 desc.
776 * 7 = 5432 desc.
864 * 4 = 3456 asc.
so the highest with a product in ascending order (I) is 864, and the highest whose product is in descending order (II) is 776.
|
Posted by Charlie
on 2012-08-20 12:26:50 |