I have a perl script to which I need to add a capability that is well beyond my current thinking ability. I am not even sure where to look for suggestions. I will try to state the problem and would like any suggestions as to where to start in coding or where to look for information on solving this sort of problem. It is sort a big puzzle.
I have a number of sizes of weights, for argument purposes (in actuality they will be decimal values with many places), say they are .01 .12 1.1 2.2 5.3 10.5 50.1 100.6 gram. each weight will also have a known precision but that complexity will only be used in the program once I figure out the basics.
I need to write a program that calculates the smallest total number of weights to use to obtain a total that is as close to a desired as possible. If it were all in whole numbers it would be trivial. The reason I can not just use a huge number of the smallest weight is because each weight has an allowable error and if a huge number is used, the possible error also gets huge. My current program demonstrates this very well.
I have a script that does the calculations with the actual weights i will be using but the user has to use a trial and error process to attempt to get the closest match with the best precision and it involves lots fiddling and no assurance of the best solution. I could probably keep playing with the script and maybe get a clue as to what my thinking is, as a relatively intelligent human, and try to write a program to mimic what I have found to be a good approach but i think i would be using intuition and have no idea how to program that. I could probably do it by brute force but also do not know how to approach that either.