If predicates keep order in arrays (for example, with your example, if all values ββare guaranteed non-negative), you can adapt the merge algorithm. Consider the key for each array as the final value (what you get after applying the predicate as many times as necessary for all arrays).
If the predicate does not preserve order (or the arrays are not ordered for starters), you can first sort it by the final value, but the need to do this suggests that a different approach might be better (for example, a hash of the table suggested elsewhere).
Basically, check if the following final value is equal for all arrays. If not, go to the lowest (in only one array) and repeat. If you get all three equal, this is a (possible) solution - go all three before looking for the next one.
A βpossibleβ solution, because you may need to check - if the predicate function can map more than one input value to the same output value, you may have a case where the value is found in some arrays (but not in the first or last) is wrong.
EDIT - there can be big problems when the predicate does not display each input in a unique result - it cannot think at the moment. Basically, a merge approach may work well, but only for certain types of predicate function.
source share