Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #142893

Re: Application Exercises

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Application Exercises
Date 2019-04-08 01:24 +0100
Organization A noiseless patient Spider
Message-ID <87zhp1e42s.fsf@bsb.me.uk> (permalink)
References <exercise-20190406184435@ram.dialup.fu-berlin.de> <87r2aeg3be.fsf@bsb.me.uk> <86wok6l2ce.fsf@mailhub.linuxsc.com>

Show all headers | View raw


Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>
>>>   Disclaimer:  I might have posted about the same programming
>>>   problem some years ago.  But then it was my own invention,
>>>   while now I read about it in a book.
>>>
>>>   In a book about the job application as a programmer, I found
>>>   a paragraph, were they say that application exercises often
>>>   enforce arbitrary restrictions, which do not make sense
>>>   according to the author of this book, but the exercises have
>>>   to be done nevertheless.  As an example he gave:
>>>
>>> |Write a function to detect whether two integral numbers are
>>> |equal without using any comparison operators.
>>>
>>>   . As a hint he wrote:  "Think of bit operators.".
>>
>> I think that's a bad hint.  It points towards thinking about
>> representations and not values, which looks to me to be the rockier
>> road.
>>
>> I'm thinking along these lines:
>>
>>  #define CMP(a, b) !((unsigned)(a) - (unsigned)(b))
>>
>>  CMP(a/2, b/2) && CMP(a - a/2, b - b/2)
>
> An interesting (and nice!) idea.  How about
>
>     CMP(a/5, b/5) && CMP(a%5, b%5)
>
> instead?  (The choice of 5 is arbitrary, except that I
> wanted to be well away from the boundary of the bad
> ranges.)  Using the / and % I find it easier to convince
> myself it's correct.

Yes, I like that.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Application Exercises Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-06 23:46 +0100
  Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-07 00:08 -0700
    Re: Application Exercises Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-08 01:24 +0100

csiph-web