Thanks! Not quite yet! Each number can appear once in each column in the end output! This would work for cases where those pair do not overlap. The problem comes in cases like @xa=(900,1000,1010,2040,2010,8000,9999); @xb=(899,1005,1022,2020,2000,6000,9999,20000);
I guess I have to track the various pairs of $i and $j if there are multiple pairs for a particular $diff, and find the minimum sum(abs($diff)) at the end, but not sure what data structure would be better for the job. Nengbing David wrote: > Nengbing Tao wrote: > > -90 8765 8675 > > 90 1234 1324 > > -198 4765 4567 > > > > Notice that |1500-1485|=|1500-1515|. > > > how can you have negative if they are abs? anyway, have you try: > #!/usr/bin/perl -w > use strict; > my @xa=(8765,6000,4765,3000,1530,1500,1465,1234,1000); > my @xb=(8675,6000,4567,3100,3000,1545,1515,1485,1324,1005); > my %hash; > for my $i (@xa){for my $j (@xb){push(@{$hash{abs($i-$j)}},"$it$j")}}; > for my $diff (sort {$a <=> $b} keys %hash){ > print "$difft$_n" for(@{$hash{$diff}}); > } > __END__ > prints: > 0 6000 6000 > 0 3000 3000 > 5 1000 1005 > 15 1530 1545 > 15 1530 1515 > 15 1500 1515 > 15 1500 1485 > 20 1465 1485 > 45 1530 1485 > 45 1500 1545 > 50 1465 1515 > 80 1465 1545 > .... etc > not sure if that's what you want... > david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]