in reply to Multi-Threaded Elevator Simulator
is shorter and more clearly written as:# join the people threads and collect statistics my ($total_wait, $total_ride, $max_wait, $max_ride) = (0,0,0,0); foreach (@people) { my ($wait1, $wait2, $ride1, $ride2) = $_->join; $total_wait += $wait1 + $wait2; $total_ride += $ride1 + $ride2; $max_wait = $wait1 if $wait1 > $max_wait; $max_wait = $wait2 if $wait2 > $max_wait; $max_ride = $ride1 if $ride1 > $max_ride; $max_ride = $ride2 if $ride2 > $max_ride; }
in the Elevator class, the constant STARTING is declared and never used.# join the people threads and collect statistics my ($total_wait, $total_ride, $max_wait, $max_ride) = (0,0,0,0); foreach (@people) { my ($wait1, $wait2, $ride1, $ride2) = $_->join; $total_wait = $wait1 + $wait2; $total_ride = $ride1 + $ride2; $max_wait = $wait1 > $wait2 ? $wait1 : $wait2; $max_ride = $ride1 > $ride2 ? $ride1 : $ride2; }
as an aside: in new york city, there are three buildings with double-decker elevators (i've worked in two of them.) lobby and mezzanine are the base levels, and when going up you must use the lobby for odd floors (L 3 5 7 ... ) and mezzanine for odd floors (M 4 6 8 ...). going down, you can reach any floor from either level (except the edge case at the bottom.) i believe the Elevator class can be easily subclassed to handle this scenario as well. cool.
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Multi-Threaded Elevator Simulator
by samtregar (Abbot) on Aug 07, 2002 at 14:31 UTC | |
by dimmesdale (Friar) on Aug 08, 2002 at 14:41 UTC | |
by samtregar (Abbot) on Aug 09, 2002 at 20:45 UTC | |
by Anonymous Monk on Aug 07, 2002 at 22:45 UTC | |
by merlyn (Sage) on Aug 07, 2002 at 22:56 UTC | |
by BrentDax (Hermit) on Aug 09, 2002 at 22:29 UTC |