DECLARE FUNCTION SimulateDrivers! (numDr!, NumSim!) DECLARE FUNCTION CloseEnough! (T!(), D!) NumSim = 5000 numDr = 2 CLS PRINT STRING$(80, 177) PRINT "This program simulates cars arriving at the intersection within one minute" PRINT "They have to stop if arrive within 5 sec of another car. It is interesting to check how often all go through without stopping." PRINT STRING$(80, 177) PRINT "# cars", "Chances nobody stops" FOR numDr = 2 TO 10 PRINT numDr, USING "#.###"; SimulateDrivers(numDr, NumSim) / NumSim NEXT FUNCTION CloseEnough (T(), D) 'check if times are close enough n = UBOUND(T) FOR i = 1 TO n FOR j = i + 1 TO n IF ABS(T(i) - T(j)) < D THEN stp = -1 NEXT NEXT CloseEnough = stp END FUNCTION FUNCTION SimulateDrivers (numDr, NumSim) 'how often all drivers did get through? DIM T(numDr) FOR j = 1 TO NumSim FOR k = 1 TO numDr T(k) = RND(1) NEXT k IF NOT CloseEnough(T(), 5 / 60) THEN Through = Through + 1 NEXT j SimulateDrivers = Through END FUNCTION