[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Horrible algorithm



Here is a simplification which I think maps in a more obvious fashion
the algorithm's intent. The loop iterates on @A only, and two
variables are used to keep track of range limits.

  my (@alist, @blist, $highA, $highB);
  while (@A) {
    push @alist, $highA = shift @A;
    shift @B while $B[0] < $highA;
    push @blist, $highB = shift @B while $B[0] <= $highA + $D;
    unless (@A && $A[0] <= $highB) {
      print "alist = @alist   blist = @blist\n" if @blist;
      @alist = @blist = ();
    }
  }

-- 
Luc St-Louis
lucs@cam.org

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org