Two cars leave simultaneously from points X and Y on the same road but in opposite directions. Their speeds are constant, and in the ratio 5 to 4 with the car leaving at X being the faster of the two.
The cars travel to and fro between X and Y. They meet for the second time at the 145th milestone and for the third time at the 201st milestone.
What are the respective milestones at X and Y?
DEFDBL AZ
FOR x = 0 TO 600
FOR y = 0 TO 600
IF x < y THEN low = x: high = y: ELSE low = y: high = x
IF ABS(x  y) > 55 AND low < 145 AND high > 201 THEN
c5 = x: c4 = y
c5dir = 5 * SGN(y  x)
c4dir = 4 * SGN(x  y)
mtg = 0
good = 1
DO WHILE mtg < 3
c5 = c5 + c5dir
IF c5 < low THEN c5 = low + ABS(c5  low): c5dir = c5dir
IF c5 > high THEN c5 = high  (c5  high): c5dir = c5dir
c4 = c4 + c4dir
IF c4 < low THEN c4 = low + ABS(c4  low): c4dir = c4dir
IF c4 > high THEN c4 = high  (c4  high): c4dir = c4dir
IF c4 = c5 THEN
mtg = mtg + 1
IF mtg = 2 AND c4 <> 145 OR mtg = 3 AND c4 <> 201 THEN
good = 0
EXIT DO
END IF
END IF
LOOP
IF good THEN PRINT x, y
END IF
NEXT
NEXT
finds the milestones at 103 and 229

Posted by Charlie
on 20131011 00:35:06 