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

Michael Field hamster at snap.net.nz
Mon Aug 1 11:17:29 BST 2011


Hum, Is it just me or does it not really work as expected for half the 
values of 'x'? Maybe the return type needs to be "unsigned long long" 
and the last line "return (unsigned long long)x+1;" (if such a horrible 
type exists in GCC...

Might use it to drive a few LEDs sometime.

If we are not careful we might end up discussing  Project Euler 
solutions... I liked problem 215 
(http://projecteuler.net/index.php?section=problems&id=215 
<http://projecteuler.net/index.php?section=problems&id=215>).

Mike


On 1/08/2011 7:47 p.m., Cass Jones wrote:
> Not trying to break the time frame rules, but @Mark, I would imagine
> it only returns 1 if x is 1, otherwise it returns 0, assuming a 32 bit
> or less integer
>
> On Mon, Aug 1, 2011 at 5:59 PM, Mark Atherton<markaren1 at xtra.co.nz>  wrote:
>> Hi Andre,
>>
>> returns 1
>>
>> Haven't seen you for years, hope you are well.
>>
>> Regards,
>>
>> Mark Atherton
>>
>> At 04:09 p.m. 1/08/2011, you wrote:
>>> 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;
>>> }
>>>
> _______________________________________________
> 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.
>




More information about the Chchrobotics mailing list