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*
In reply to Re: Multi-Threaded Elevator Simulator
by particle
in thread Multi-Threaded Elevator Simulator
by samtregar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |