From: Brian Candler Date: 2010-08-17T21:25:02+09:00 Subject: Re: can i do this in ruby? a simulation process Andrew Wagner wrote: > Anyway, I did this, for fun, and consistently got an average of around > 833 > seconds on average for 100000 trials. Anyone else give this a shot? I'm > curious to see whether different implementations give different results. Ruby quiz :-) After 10,000 trials I got an average of 803 seconds, and after a second 10,000 trials I got 807 seconds. But I don't think we should post any code until the OP has had a go. I would certainly expect wide variation between runs, since it would be affected very strongly by when the buses set off. However I think the point of the exercise is really the simulation, because it becomes very simple if you treat it statistically. (1) Average number of occupants per vehicle = 0.2*1+0.3*2+0.1*3+0.1*4+0.3*40 = 13.5 (2) You can ignore the different travel times. The average rate at which vehicles depart must be the same as the average rate at which they arrive (law of conservation of vehicles) (3) The vehicles depart on average every 20 seconds So you should get an average of 0.675 passengers per second, which implies 500 passengers will pass any particular point after 740.7 seconds. It then takes each passenger an average of 60 seconds to get from A to B, so that makes 800.7 seconds for the original question. I would expect the real simulation answer to be slightly different because of the discontinuous (bursty) nature of arrivals. -- Posted via http://www.ruby-forum.com/.