From: Brian Candler Date: 2010-08-18T18:25:15+09:00 Subject: Re: can i do this in ruby? a simulation process Josh Cheek wrote: > For each second, check to > see > if a vehicle should be departing, if so, add it to an array of vehicles > in > transit. And check the array of vehicles in transit to see if a vehicle > is > arriving, if so, remove it from the in transit array, and add its > passengers > to a sum. Then just increment seconds and iterate until >= 500 > passengers > have arrived. You have to be very careful with the termination condition. Let's say that a car leaves, arrives after 70 seconds, and that brings increments your total from 499 to 500. However it's still possible that another vehicle could leave 5 seconds later and arrive after 50 seconds (15 seconds before that car), which means the 500 limit is actually reached earlier than you first thought. Regards, Brian. -- Posted via http://www.ruby-forum.com/.