Did you try my algorithm at Re^2: NP-complete sometimes isn't (A benchmark)? It is guaranteed to always find the best possible answer. It has no bug with repeated numbers. It is not the fastest option, but it may well be fast enough for your purposes. | [reply] |
Hey tilly,
I haven't tried that one. In fact I hadn't even notice there was another node with that theme! I looked for hours before my first post, but I guess the name of the node didn't appeal to me, since I did not even know about teh existence of NP-complete problems.
It's pretty long and seems slow but it may be the answer to my prays. I hope it doesn't take days... I'll try it. Thanks. Pepe.
| [reply] |
| [reply] |
Sorry. I never got back to checking the fix properly.
Would you please try replacing the last line with this (note:pre-decrement not post-decrement).
return \@best, [ grep{ !exists $seen{ $_ } or !--$seen{ $_ } } @$a
+Ref ];
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Sorry
It seems to do worse. Some of the elemenents appear if both of the resulting subarrays
| [reply] |
Grr! Intersection & difference of arrays is something that ought to be in core.
Looked in List::MoreUtils to no avail.
I looked at cpan and downloaded Array::Utils but it can't handle duplicates.
Looked at List::Compare, but it comes complete with the kitchen sink & waste disposal (aliased as Belfast Sink & waste bin) and calculates 20 different things under the guise of "initalising".
Could you post an example of input array and expected outputs please.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |