[chbot] New chocolate fish challenge

hamster hamster at snap.net.nz
Wed Nov 19 04:47:32 GMT 2014


 

Loops are allowed, looking pretty good! 

Mike 

On 19.11.2014
17:35, Andre Renaud wrote: 

> Hi Mike,
> Are you allowed loops? You can
implement addition using <<, &, ^. So:
> 
> static int inc(int x)
> {
>
int y = 1;
> while (y) {
> int carry = x & y;
> x = x ^ y;
> y = carry
<< 1;
> }
> return x;
> }
> 
> int fish(void)
> {
> static unsigned char
b = 0;
> 
> b = inc(b);
> if (b == 60) {
> b = 0;
> return 1;
> }
>
return 0;
> }
> 
> More than 10 lines though. Essentially it's just the
naive solution
> with b++ 'unpacked' into binary operators.
> 
> Andre


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20141119/37de2925/attachment.html>


More information about the Chchrobotics mailing list