sanku has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, i am having two arrays as @start and @end in @start array contains the following values @start=('8:20:21','8:20:21','8:21:23','8:22:01','8:50:00','8:53:00') and in @end array contains the following values @end=('8:21:35',8:21:56','8:22:00'); and i need the count of peak hour for example: the peak hour is 3 as (8:20:21,8:20:21,8:21:23) are occur at same time can any one suggest me about this how to calculate the peak hour count thanks in advance

Replies are listed 'Best First'.
Re: calculating peak hour
by dsheroh (Monsignor) on Jul 16, 2009 at 10:53 UTC
    From the comments so far, I gather that what you're looking for is the maximum number of 'start-to-end' time periods which are in progress within your dataset. This is easily calculated, given that the number of open time periods increments at each @start time and decrements at each @end time:
    my @proc_start = sort @start; my @proc_end = sort @end; my $count = 0; my $max = 0; while (@proc_start && @proc_end) { if ($proc_start[0] lt $proc_end[0]) { # Next event is a start $count++; $max = $count if $count > $max; shift @proc_start; } else { # Next event is an end $count--; shift @proc_end; } } print "Peak was $max\n";
    (Untested code. Assumes that the time period covered by the dataset begins and ends with 0 open periods. Hour-to-hour transitions are left as an exercise for the reader.)
Re: calculating peak hour
by Anonymous Monk on Jul 16, 2009 at 04:40 UTC
    what is definition of peak hour?
      Peak hour is to calculate the count of number of calls happened simultaneously in each and every hour.
        Since 8:20:21 and 8:21:23 are not simultaneous, you need to clarify definition.
Re: calculating peak hour
by spx2 (Deacon) on Jul 16, 2009 at 05:39 UTC
    What have you tried in order to solve the problem ?
Re: calculating peak hour
by Jenda (Abbot) on Jul 16, 2009 at 09:46 UTC

    Only the first three calls ever ended? And you define "peak hour" as the maximum number of simultaneous calls or what???

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.