# Need Help Simulation in ruby

**URL:** <https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225>\
**Category:** Ruby\
**Created:** [September 20, 2010, 8:46am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225 "2010-09-20T08:46:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 20, 2010, 8:46am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/1 "2010-09-20T08:46:12Z")

</div>

Hi everyone can someone help me with my simulation program:

Here is the problem:  
An Ambulance are dispatched at a rate of one every 15 + 10 minutes in a  
large metropolitan area. Fifteen percent of the calls are false alarm  
which requires 12 + 2 minutes to complete. All other calls can be one of  
two kinds. First kind are classified as serious. They constitute 15% of  
the non-false alarm calls and take 25 + 5 minutes to complete. The  
remaining call take 20 + 10 minutes to complete. Assume that there are  
very large number of available ambulance, and that any number can be on  
call at any time. Write a program that would simulate the systemâ€™s 500  
call to be completed.

i think it is similar to this topic:  
[http://www.ruby-forum.com/topic/215134#new](http://www.ruby-forum.com/topic/215134#new)

---

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 20, 2010, 9:05am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/2 "2010-09-20T09:05:03Z")

</div>

Steven Boss wrote:

> Hi everyone can someone help me with my simulation program:
> 
> Here is the problem:  
> An Ambulance are dispatched at a rate of one every 15 + 10 minutes in a  
> large metropolitan area. Fifteen percent of the calls are false alarm  
> which requires 12 + 2 minutes to complete. All other calls can be one of  
> two kinds. First kind are classified as serious. They constitute 15% of  
> the non-false alarm calls and take 25 + 5 minutes to complete. The  
> remaining call take 20 + 10 minutes to complete. Assume that there are  
> very large number of available ambulance, and that any number can be on  
> call at any time. Write a program that would simulate the systemâ€™s 500  
> call to be completed.
> 
> i think it is similar to this topic:  
> [Can i do this in ruby? a simulation process - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/215134#new)

i tried to start from scratch so:

Ambulance(Dispatch Rate) â€“ 15sec -\>10 Minutes  
1 False alarm Calls(15%) â€“ 12sec → 2Minutes  
1 Non-False alarm(15%) â€“ 25sec → 5minutes  
Normal Calls â€“ 20sec → 10minutes

---

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 20, 2010, 10:27am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/3 "2010-09-20T10:27:08Z")

</div>

Steven Boss wrote:

> Here is the problem:  
> An Ambulance are dispatched at a rate of one every 15 + 10 minutes in a  
> large metropolitan area. Fifteen percent of the calls are false alarm  
> which requires 12 + 2 minutes to complete. All other calls can be one of  
> two kinds. First kind are classified as serious. They constitute 15% of  
> the non-false alarm calls and take 25 + 5 minutes to complete. The  
> remaining call take 20 + 10 minutes to complete. Assume that there are  
> very large number of available ambulance, and that any number can be on  
> call at any time. Write a program that would simulate the systemâ€™s 500  
> call to be completed.
> 
> i think it is similar to this topic:  
> [Can i do this in ruby? a simulation process - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/215134#new)

Yes, remarkably similar.

My advice to you would be the same: start by doing the simulation _by  
hand_, using paper and pencil. Do it for at least 5 ambulances so that  
you can be clear about the sequence of actions. Then automate that  
sequence.

The question seems ambiguous in several ways, so as you do it, write  
down what interpretation you have chosen. For example, what does “15 +  
10 minutes” mean? Perhaps it means 15 +/- 10 minutes (i.e. 5 to 25), or  
between 15 and 15 + 10 (i.e. 15 to 25). Is this a linear distribution,  
i.e. all times equally likely? Is it discrete (exactly 5 or 6 or … 25  
minutes), or continuous (any fractional value between 5.0 and 25.0)?

---

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 21, 2010, 6:33am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/4 "2010-09-21T06:33:17Z")

</div>

Just to Clarify:

An Ambulance are dispatched at a rate of one every 15sec to 10 minutes  
in a  
large metropolitan area. 15% of the calls are false alarm  
which requires 12sec to 2 minutes to complete. All other calls can be  
one of  
two kinds. First kind are classified as serious. They constitute 15% of  
the non-false alarm calls and take 25sec to 5 minutes to complete. The  
remaining call take 20sec to 10 minutes to complete. Assume that there  
are  
very large number of available ambulance, and that any number can be on  
call at any time. Write a program that would simulate the systemâ€™s 500  
call to be completed.

Ok so i need to loop numbers from 1 -500 for the ambulance  
then set a three type of calls  
-\> False Alarm Calls (it takes 12sec to 2 minutes to process the  
calls)  
-\> Non-False Alarm Calls (it takes 25sec to 5 minutes to process the  
calls)  
-\> Normal Calls (it takes 20sec to 10 minutes)

after getting a call i need to add the dispatch rate of an ambulance for  
15sec to 10minutes  
Example i’ll put it in a Table:  
Ambulance # / Time(Call Received)/Time(Process Request)/Call Type/Time  
Dispatch / Total Time

em i correct sir?

---

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 21, 2010, 5:51am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/5 "2010-09-21T05:51:54Z")

</div>

Brian C. wrote:

> My advice to you would be the same: start by doing the simulation _by  
> hand_, using paper and pencil. Do it for at least 5 ambulances so that  
> you can be clear about the sequence of actions. Then automate that  
> sequence.
> 
> The question seems ambiguous in several ways, so as you do it, write  
> down what interpretation you have chosen. For example, what does “15 +  
> 10 minutes” mean? Perhaps it means 15 +/- 10 minutes (i.e. 5 to 25), or  
> between 15 and 15 + 10 (i.e. 15 to 25). Is this a linear distribution,  
> i.e. all times equally likely? Is it discrete (exactly 5 or 6 or … 25  
> minutes), or continuous (any fractional value between 5.0 and 25.0)?

thx for the response i’ll try your advice thanks brain

cheers

---

<div class="post-metadata">

**Author:** ![stevenbristol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@stevenbristol](https://www.ruby-forum.com/u/stevenbristol)\
**Post date:** [September 21, 2010, 10:56am UTC](https://www.ruby-forum.com/t/need-help-simulation-in-ruby/195225/6 "2010-09-21T10:56:59Z")

</div>

Steven Boss wrote:

> Just to Clarify:
> 
> An Ambulance are dispatched at a rate of one every 15sec to 10 minutes  
> in a  
> large metropolitan area. 15% of the calls are false alarm  
> which requires 12sec to 2 minutes to complete. All other calls can be  
> one of  
> two kinds. First kind are classified as serious. They constitute 15% of  
> the non-false alarm calls and take 25sec to 5 minutes to complete. The  
> remaining call take 20sec to 10 minutes to complete. Assume that there  
> are  
> very large number of available ambulance, and that any number can be on  
> call at any time. Write a program that would simulate the systemâ€™s 500  
> call to be completed.
> 
> Ok so i need to loop numbers from 1 -500 for the ambulance  
> then set a three type of calls  
> -\> False Alarm Calls (it takes 12sec to 2 minutes to process the  
> calls)  
> -\> Non-False Alarm Calls (it takes 25sec to 5 minutes to process the  
> calls)  
> -\> Normal Calls (it takes 20sec to 10 minutes)
> 
> after getting a call i need to add the dispatch rate of an ambulance for  
> 15sec to 10minutes  
> Example i’ll put it in a Table:  
> Ambulance # / Time(Call Received)/Time(Process Request)/Call Type/Time  
> Dispatch / Total Time
> 
> em i correct sir?

As I said before, I’d replicate exactly what you’d do on paper. For  
example, I suspect that on each piece of paper you’d mark the time which  
the call arrived, the type of call it was, and the time it took to  
complete (or end time).

Re-reading the question, it is still highly ambiguous. It starts by  
saying that an ambulance is _dispatched_ every N seconds, and I would  
imagine that each ambulance is only dispatched in response to a call.  
But presumably you would not dispatch an ambulance in response to a  
“false alarm” call? So does it actually mean that a call is received  
every N seconds, rather that an ambulance is dispatched every N seconds?

Or you are supposed to estimate the rate of incoming calls, working  
backwards from the rate of ambulance dispatch and the proportion of  
non-false alarms?

Another interpretation is that every call results in an ambulance being  
dispatched, and the crew decide it’s a false alarm only once they’ve  
arrived and assessed the situation. But then, all calls would take the  
same amount of time to process, since you wouldn’t know at call time  
whether it was a false alarm or not.
