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

Andre Renaud andre at bluewatersys.com
Mon Aug 1 19:52:58 BST 2011


Hi Mike,
There are definitely input values that won't give a valid answer. However if both the input & output are representable in 32-bits then I think it works properly.

Regards,
Andre

On 1/08/2011, at 10:17 PM, Michael Field <hamster at snap.net.nz> wrote:

> 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.
>> 
> 
> 
> _______________________________________________
> 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