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


Groups > comp.lang.c > #142918

Re: Application Exercises

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 Tue, 09 Apr 2019 04:35:56 -0700
Organization A noiseless patient Spider
Lines 31
Message-ID <86pnpvjtr7.fsf@mailhub.linuxsc.com> (permalink)
References <exercise-20190406184435@ram.dialup.fu-berlin.de> <T86qE.57301$hJ3.14005@fx07.iad>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info reader02.eternal-september.org; posting-host="6fb794e524592612d1f12901ed425102"; logging-data="10563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1909WeEhR/eztQr5un/9/m4Qf+t1s/xh9M="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:J6WZpALomY9hN/EOyphXw+3ogAQ= sha1:dXZ0otuAgzypKchc3TPpe9WDDY0=
Xref csiph.com comp.lang.c:142918

Show key headers only | View raw


Richard Damon <Richard@Damon-Family.org> writes:

> On 4/6/19 2:01 PM, Stefan Ram wrote:
>
>> |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.".
>>
>>   Ok, I have an idea how I might do this, which I might post
>>   later.  I am not sure whether my idea is correct.  I need to
>>   write a test.  Or maybe a proof?
>>
>>   The book did not refer to C, but C is the most popular
>>   programming language (or may be at least one of the most
>>   popular programming languages), and the book mentioned
>>   "bit operators".
>
> The one thought I had was if (i^j), you could also use if(i-j)
>
> To detect something, you need some form of test, but if, or
> conversion to bool have an implied comparison to zero, which
> isn't considered a comparison operator.

Challenge problem:  write a signed-integer equality determiner
without using any comparisons:  no comparison operators, no
conversions to bool, no &&, ||, or ?:, no if()'s, for()'s,
or while()'s, and (the sneaky one) no switch()'s.  A nice
little problem.  The gold standard is a solution that works
on any conforming implementation.

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


Thread

Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-06 14:23 -0400
  Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 04:35 -0700
    Re: Application Exercises Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-09 13:29 +0100
      Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 08:02 -0700
    Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-09 22:15 -0400
      Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-09 20:55 -0700
        Re: Application Exercises Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-04-09 22:21 -0600
          Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-10 06:31 -0400
          Re: Application Exercises James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-10 07:43 -0400
        Re: Application Exercises Richard Damon <Richard@Damon-Family.org> - 2019-04-10 06:40 -0400
          Re: Application Exercises Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-04-10 08:15 -0700
      Re: Application Exercises James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-10 07:37 -0400

csiph-web