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


Groups > comp.lang.c > #142918

Re: Application Exercises

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Application Exercises
Date 2019-04-09 04:35 -0700
Organization A noiseless patient Spider
Message-ID <86pnpvjtr7.fsf@mailhub.linuxsc.com> (permalink)
References <exercise-20190406184435@ram.dialup.fu-berlin.de> <T86qE.57301$hJ3.14005@fx07.iad>

Show all headers | 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