Search algorithm but for functions
algorithm, python
Solution
Without any further information on the functions, the results of the `len(functions) * len(values)` possible function calls must be considered independent from each other, so there is no faster way than checking them all.
You can write this a little more concisely, though:
any(f(v) for v in values for f in functions)
The builtin function `any()` also short-circuits, just like your original code.
Edit: It turns out that the desired equivalent would have been
all(any(f(v) for f in functions) for v in values)
See the comments for a discussion.
Problem
Given a list of input (let's say they are just integers), and a list of functions (and these functions takes an integer, and returns either True or False). I have to take this list of input, and see if any function in the list would return True for any value in the list. Is there any way to do this faster than O(n^2) Right now what I have is ``` for v in values: for f in functions: if f(v): # do something to v break ``` Any faster methods?