I have a function with two inputs x
and y
which returns z
based on some conditions (which rely on the values of x
and y
). Something similar to the following pseudocode.
f(x, y)
if x < a && y < b
return z=x+y;
else if x >= a && x < c && y >= b && y < d
return z=x-y;
else x >= c && y >= d
return z=x*y;
Now I want to write a function which almost acts as the inverse function for f
(Let's call it g
). The pseudocode should look like something similar to this:
g(z)
return x1, x2, y1 and y2; //x's, y's are corresponding boundaries for given z
Assume that f
is very very simple and based only on a few conditions and the return value is just as simple as some arithmetic statements (exactly similar to what is provided above). How do you write g
? Do you simply store boundaries and corresponding return values from f
and then traverse between them with the given z
to find the appropriate boundaries? I'm trying to see how other people hack this. Note that f
is also written by yourself and you know everything about it.
NOTE: Assume that return values are distinct at all times and don't have any overlap in any situations