Reputation: 523
I want to find the second minimum for three numbers.
I have a blackbox that gets two input numbers, the blackbox returns the max between numbers.
Additionally, I have a blackbox that returns the min.
Now I have a box that gets 3 numbers as input and it needs to return the second min.
Can you help me to solve this? How can I solve this by only using the two blackboxes?
Thanks!
Upvotes: 2
Views: 116
Reputation: 8743
Inputs: a, b, c
Level 1 (filtering out the biggest value):
min(a,b) -> min_ab
min(a,c) -> min_ac
min(b,c) -> min_bc
Level 2 (selecting the highest remaining value, step 1):
max(min_ab, min_bc) -> m*
Level 3 (step 2):
max(m*, min_ac) -> solution
Gives a total of 5 boxes.
a --+--\
| min --\
b -----< max --\
| min --/ max --
c -----< /
| min --------/
\--/
Alternatively you can do 3 maxes first and then 2 mins.
Upvotes: 1
Reputation: 21
I can see of a way to to this with 3 uses of the blackbox. Let's pretend each element is a,b,c. Find the min of a with b and b with c. You then find the max of those 2 answers and you have the second min. If only b was returned, you find the min of a and c.
Upvotes: 1