[chbot] !!!!!!!! Choc fish challenge 2 !!!!!!!!!

Andre Renaud andre at bluewatersys.com
Mon Aug 1 05:09:47 BST 2011


To make up for my massive blunder, I'll offer a replacement fish for an
explanation of what the following algorithm does. We'll go with the same
timeframe as before, and I'll endeavor not to reply myself.

unsigned int function(unsigned int x)
{
  x--;
  x |= x >> 1;
  x |= x >> 2;
  x |= x >> 4;
  x |= x >> 8;
  x |= x >> 16;
  return x + 1;
}

Regards,
Andre

On 01/08/11 15:54, Mark Beckett wrote:
> And I thought I had trouble reading
> 
> This time the first correct answer after  8pm on Tuesday will win.
> 
> 
> Mark
> 
> 
> 
> On 1/08/11 14:57, Andre Renaud wrote:
>> Hi Charles,
>>
>> On 01/08/11 14:13, Charles Manning wrote:
>>> Under what conditions does the following compile and what will happen when it
>>> executes?
>>>
>>>    while(x[j] == j[x]){
>>> 	j++; x++;
>>>    }
>> As far as I can tell, one of x or j has to be an ordinal/integer type.
>> The other has to be some kind of array type. Since array indexing
>> essentially becomes addition, x[j] is equivalent to j[x]. I think this
>> means that it'll run forever.
>>
>> However, I'm not entirely convinced that typing of x[j] vs j[x] doesn't
>> come into it, especially if the one of them that is an array has
>> sizeof()>  1.
>>
>> Regards,
>> Andre
>>
>> _______________________________________________
>> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
>> http://lists.ourshack.com/mailman/listinfo/chchrobotics
>> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
>> Web site: http://kiwibots.org
>> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm
>>
>> When replying, please edit your Subject line to reflect new content.
>>
> 
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Web site: http://kiwibots.org
> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm
> 
> When replying, please edit your Subject line to reflect new content.


-- 
Bluewater Systems - An Aiotec Company

Andre Renaud        		
andre at bluewatersys.com          5 Amuri Park, 404 Barbadoes St
www.bluewatersys.com            PO Box 13 889, Christchurch 8013
www.aiotec.co.nz                New Zealand
Phone: +64 3 3779127            Freecall: Australia 1800 148 751
Fax:   +64 3 3779135            USA 1800 261 2934



More information about the Chchrobotics mailing list