Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #142882
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: Application Exercises |
| Date | Sun, 07 Apr 2019 00:08:17 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 37 |
| Message-ID | <86wok6l2ce.fsf@mailhub.linuxsc.com> (permalink) |
| References | <exercise-20190406184435@ram.dialup.fu-berlin.de> <87r2aeg3be.fsf@bsb.me.uk> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="efcb04d8ed63c58ddf57a05b4b8ba79a"; logging-data="6653"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xxm2VV6ygdfdDL/tSsPZr2iVSLwBgKVc=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:w1SVtSSzF/eF/y+V15zTcpAvn3s= sha1:kN/0qZHJKKEsf6eKtQFgfD1rSx0= |
| Xref | csiph.com comp.lang.c:142882 |
Show key headers only | View raw
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.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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