Saul was driving to work one day, when he glanced at his car's dashboard and noticed something interesting about his mileage indicators. His odometer, which shows the miles driven since the car was manufactured, hit 12,345.6 miles, and his trip meter read 123.4 miles. So, the meter matches the first four digits on the odometer.
(i) How far must Saul drive - before this happens again?
(ii) What is the smallest distance that Saul can drive so that the two odometers have all ten digits between them, but share no digits in common?
DEFDBL A-Z
trip = 1234
odo = 123456
travelled = 0
DO
trip = trip + 1
IF trip > 9999 THEN trip = trip - 10000
odo = odo + 1
IF odo > 999999 THEN odo = odo - 1000000
travelled = travelled + 1
LOOP UNTIL odo \ 100 = trip
PRINT odo; trip, travelled
trip = 1234
odo = 123456
travelled = 0
DO
trip = trip + 1
IF trip > 9999 THEN trip = trip - 10000
odo = odo + 1
IF odo > 999999 THEN odo = odo - 1000000
travelled = travelled + 1
t$ = RIGHT$("0000" + LTRIM$(STR$(trip)), 4)
o$ = RIGHT$("000000" + LTRIM$(STR$(odo)), 6)
tst$ = t$ + o$
good = 1
FOR i = 1 TO LEN(tst$) - 1
IF INSTR(MID$(tst$, i + 1), MID$(tst$, i, 1)) > 0 THEN good = 0: EXIT FOR
NEXT
LOOP UNTIL good
PRINT odo; trip, travelled
finds
133557 1335 10101
132067 9845 8611
indicating that
For part (i), in 1010.1 more miles, the odometer will read 13355.7 and the trip meter 133.5.
For part (ii), in only 861.1 miles from the original scenario, the odometer will read 13206.7 and the trip meter 984.5.
|
Posted by Charlie
on 2013-03-26 14:33:03 |