All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Finding the maximum (Posted on 2004-04-21)
Using only standard math operators (+, -, *, /) and functions (absolute value, square root, powers, and so on), give a function that calculates MAX(A,B,C).

Alternate version, for programmers only: using any language (BASIC, C, Excel, whatever) find the maximum of A, B, and C, but be careful when writing the program, because you cannot use the "" key, for it's broken (thus writing things like IF A>B is impossible...) and you cannot use the "M" key either, for it's also broken (...and writing H=MAX(A,B) is also not possible.)

 See The Solution Submitted by e.g. Rating: 4.0000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 Solution | Comment 2 of 16 |
For two variables you can use this:

MAX(A,B) = (A+B+|A-B|)/2

Intuitively, (A+B)/2 is the value half way between A and B. Adding |A-B|/2 results in the larger of A and B.

For three arguments, use:

MAX(A,B,C) = MAX(A,MAX(B,C))

After some simplification you'd get

(2*A+B+C+|B-C|+|2*A-B-C-(|B-C|)|)/4

 Posted by Brian Wainscott on 2004-04-21 16:18:27

 Search: Search body:
Forums (0)