In C, you can write:

whereK = (M == N);

In Fortran, there is a LOGICAL data type. A LOGICAL variable is meant to have only the values TRUE or FALSE, but since it's typically stored in a full integer word, it's possible, at least in some implementations, to convert a logical value to an integer. Thus, you might be able to use a statement like the following:

whereK = int ( M == N )

Let's assume, however, that we cannot use logical operators or logical variables, but only the various arithmetic operations and variables available to us.

So here is the quiz. Can you write an *arithmetic* expression
in a single line of Fortran in the form

which accepts any pair of integersK = f ( M, N );

if ( M == N ) then K = 1 else K = 0 end if

*
Suggestion: It would be enough if you can come up with a function
F(I) which is 0 at 0, and 1 for all other integers, or vice versa.
*

Hats off to Jim Fink of Gettysburg College for posing this problem.

I give up, show me the solution.

Back to the puzzle page.