Poorly worded question (was Re: IsUnsigned() function?)
john c chu
chu at acsu.buffalo.edu
Mon Jul 23 02:41:05 AEST 1990
In article <3566 at sactoh0.UUCP> jak at sactoh0.UUCP (Jay A. Konigsberg) writes:
>dicovered that the correct answer is the simple one. Namely:
>if ( num < 0 ) return FALSE else return TRUE;
This is essentially Karl Heuer's return(num>=0) (or something to the
effect, sorry) which was considered the trivial solution.
>The question
>is designed to find people who will make things overly complacted
>or just don't know very much about how things work - thats where I
>got traped. I passed by the simple solution because the question
>seemed to imply that it wasn't the best. Oh well, thats why I read
>this group.
>
>In fact, the systems programmer liked the question so much, he said
>he was going to include it in his interviews in the future.
The question seems designed to find people who will mis-read questions
to find the easy way out. :-)
Seriously, there are at least 3 valid interpretations of that question.
The question originally stated that they wanted a function to return a
0 if an integer is signed or a 1 if it is unsigned.
Interpretation 1: return a 0 if the integer is of type int, return a 1
if it is of unsigned int (this can only be done by macro, right?)
Interpretation 2: return a 0 if the integer is less than zero, else
return a 1 (this is what they wanted and has been called the trivial
solution by the net).
Interpretation 3: technically, all numbers are 'signed' (positive or
negative) except 0, so it should return a 0 for all numbers except 0
for which it should return a 1. (e.g. return(num = 0))
I've come up with a new plausible interpretation each time I've read
the original post (they came in the order listed above). IMHO, this
question has too many interpretations to be a good question without
some clarification. (Or perhaps it was intentional, so that they can
find the people who think their way. I personally would have ended up
implementing Interpretation 3.)
john
chu at autarch.acsu.buffalo.edu
More information about the Comp.lang.c
mailing list