Problem Description
Given:
- a function \$f(a, b, c, d, e) = \frac{a \times b}c + \frac de\$
- an array \$x = [x_1, x_2, x_3, x_4, ..., x_n]\$ of non-distinct integers
- a target value \$k\$
What is the most efficient way, in terms of worst-case \$n\$, to find 5 distinct indices \$x_a, x_b, x_c, x_d, x_e\$ from \$x\$ such that \$f(x[x_a], x[x_b], x[x_c], x[x_d], x[x_e]) = k\$?
Example solutions
Example 1 (single solution):
\$x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], k = 5\$
Solution 1:
\$[1, 4, 2, 9, 3]\$ as \$f(x[1], x[4], x[2], x[9], x[3])\$ evaluates to \$5\$.
Example 2 (multiple solutions):
\$x = [0, -1, 1, -1, 0, -1, 0, 1], k = 0\$
Solution 2 (of many solutions):
\$[1, 2, 3, 5, 7]\$ OR \$[0, 1, 2, 4, 7]\$
Example 3 (no solution):
\$x = [0, -1, 1, -1, 0, -1, 0, 1], k = 8\$
Solution 3:
\$-1\$ (no solution)
Example 4 (intermediary floats):
\$x = [2, 3, 5, 4, 5, 1], k = 2\$
Solution 4:
\$[2, 3, 5, 4, 5]\$
k
? Also, the interchangeability ofa*b == b*a
seems important? \$\endgroup\$