I'd...
which leads to something like...
use constant START_MINS => 180; use constant PERIOD => 20; my @arrivals = qw/03:05 03:17 03:23/; @arrivals = map { as_minutes( $_ ) } @arrivals; for my $time ( START_MINS+1 .. START_MINS+8 ) { my @arrivals_this_period = grep { $_ > $time && $_ <= $time + PERIOD } @arrivals; print as_hhmm( $time ) , ": ", scalar @arrivals_this_period, "\n"; } sub as_minutes { my ( $hh, $mm ) = split /:/, shift; return $hh*60 + $mm; } sub as_hhmm { my $minutes = shift; my $hh = int $minutes / 60; my $mm = $minutes - $hh * 60; return sprintf "%02d:%02d", $hh, $mm; }
Output:
03:01: 2 03:02: 2 03:03: 3 03:04: 3 03:05: 2 03:06: 2 03:07: 2 03:08: 2
There's still the problem of your 20 minute period crossing midnight though
update: Fixed the for my $time ... line to match the output I gave
In reply to Re: computation difficulty
by FunkyMonk
in thread computation difficulty
by steph_bow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |