From: Jean-Julien Fleck Date: 2010-08-19T15:07:44+09:00 Subject: Re: can i do this in ruby? a simulation process 2010/8/18 : > On Wed, Aug 18, 2010 at 5:08 PM, Rob Biedenharn > wrote: >> OK, I know this thread is going for some kind of record, but like any good >> wreck it's so hard not to look. > > What kind of record would that be? I think Rob is talking about the number of mails in the thread (53 at the time being), which is quite impressive for such a simple question :o) >> Why isn't anyone saying "make an object"?  Well, I will! > > Well, JJ Fleck did suggest making a Vehicle class :-) Indeed. Here is what I did (with no comment and no mean value computation, to let Bruce think about what happens) class Vehicle attr_reader :departure_time,:arrival_time,:type,:passengers def initialize(present_time) @departure_time = present_time @arrival_time = @departure_time + 50 + rand(21) @type,@passengers = decide_type end def decide_type r = rand(10) return 'car',1 if r < 2 return 'car',2 if r < 5 return 'car',3 if r < 6 return 'car',4 if r < 7 return 'bus',40 end end vehicles = Array.new time = 0 500.times do vehicles << Vehicle.new(time) time = vehicles[-1].departure_time + 5 + rand(31) end sum = 0 vehicles.sort_by {|e| e.arrival_time}.each do |e| sum += e.passengers puts "#{sum} passengers were there after #{e.arrival_time} seconds" break if sum > 500 end >> http://gist.github.com/536140 > > Nice.  I like the Config class. Yes. Perhaps a bit of overkill for the given problem :o) Cheers, -- JJ Fleck PCSI1 Lycée Kléber