That is due to the hash -> array optimization. If I undo that then I get (lightly tested):
I think it works, but you should test with a bunch of random arrays to see that it gives answers as good as my previous code.
Do note, however, that if you are throwing in very random decimals in there (eg things like 43.12314 and 25.5422431) that the run-time performance is going to degrade horribly. That's because the basic problem really is NP-complete, and when the sums of various subsets can take on a great many different values (rather than being limited to a fairly small number of numbers) then the optimization that I am using to make the special case tractable breaks down. Therefore if you will have numbers that are not multiples of some fairly small fraction, you need to round them before passing them into that function. | [reply] [d/l] |
Listen tilly,
Unbelievable! Everytime there's a conflict with the other scripts yours gets it right. Hat tip to you, tilly!
I must only use it when the others fail because of the time problem, but I'm sure it will do the work right. It's gone now through 20.000 arrays and not a single problem.
Also, the decimal numbers in the values can only be .5, which I understand is fine for the script.
Thank you so much. Pepe
| [reply] |