From: mareg@csv.warwick.ac.uk (Dr D F Holt)
>Here is a problem I had to solve recently when working with an inferior
>database system. I thought others might enjoy trying it.
>
>The function f is defined on the integers in the range 0..100 by the
>rule:
>
>f(n) = 100 if 80 <= n <= 100,
>f(n) = n if 0 <= n <= 79.
>
>(In other words, students who score 80% or over are deemed to have
>learnt the material, and awarded 100%.)
>
>How do you define f with a single formula, using only the standard
>arithmetical operations, together with max(x,y) and min(x,y)?
SPOILER
f(x) = min(x,80) + min( max(x-79,0) , 1 ) * 20
g(x) = min( x+20*max(min(x+20,100)-99,0) , 100)
h(x) = x + (100-x) * max(0, min(1, x-79))
-------------------------------------------------------------------
I can do it with four operations, provided the range of the
function is restricted to the integers:
f(x) = min(min(x,20*(x-75)),100)
with two mins, one multiplication, and one subtraction.
The first min yields x for x < 79 and 20*(x-75), which is >= 100,
for x >= 80; the second min then gives x for x < 79 and 100 for
x >= 80.
--
Mark Thornquist