The following should work; I haven't had the guts to run it on your real data yet, but my mini-testset seems to result in an answer...
#!/usr/bin/perl
=cut
my @t = (
'18.930167',
'17.967469',
'0.008720',
'0.008720',
'122.640000',
'12493.320000',
'359.520000',
'288.700000',
'359.520000',
'89.880000',
'32.960000',
'56.920000',
'13.470000',
'1231.360000',
'20587.440000',
'359.520000',
'792.170000',
'629.160000',
'972.290000',
);
my $target = 843.24;
=cut
my @t = (100,2,32,4,65);
my $target = 7;
my @terms = _test($target,@t);
for my $n (0..$#terms) {
next unless $terms[$n];
print (($terms[$n]<0)?'subtract':'add');
print " value number ",$n+1," (",$t[$n],")";
print "\n";
}
print "to obtain total of $target\n";
sub _test {
my ($target,$number,@rest) = @_;
for my $term (0,$number,-$number) {
if(@rest==0) {
next unless $target == sprintf('%.2f',$sum+$te
+rm);
return ($term/$number)
}
my @terms = _test(sprintf('%.2f',$target-$term),@rest)
+;
next unless @terms;
return (($term/$number),@terms);
}
return;
}
It's a recursive algorithm that will eventually try every possibility until it finds a working set of terms... It will probably take a long time with the real dataset, so you'll want to eliminate as many terms as possible beforehand.