in the main package,
# 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;
}
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 > $wait2 ? $wait1 : $wait2;
$max_ride = $ride1 > $ride2 ? $ride1 : $ride2;
}
in the Elevator class, the constant
STARTING is declared and never used.
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*
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.