[chbot] New chocolate fish challenge

Mark Atherton markaren1 at xtra.co.nz
Wed Nov 19 03:30:31 GMT 2014


A 64 bit int with shift, bit test, and re-load would work, but that 
needs an 8 byte storage quantity...

So it has to be written in C ? Assembler not allowed ? :)

should be possible to build a 6 bit counter using xors and tests - 
basically making a counter using cascaded T type flip flops with 
lookahead carry etc. not sure if that can be done in 10 lines of code...

I think the brain may need plugging in backwards for this one.

-mark


At 03:36 p.m. 19/11/2014, you wrote:

>I'm building a jumbo LED clock (using 8" 7-segment displays) for the 
>local pool, as I can't read a small analogue clock without my 
>glasses when swimming. The PCBs are on their way from China as I type....
>
>So here is the challenge. Make a C function that usually returns 0, 
>but returns a value of 1 once in every 60 calls calls - just like this:
>
>int chocolate_fish(void)
>
>{
>
>   unsigned counter = 0;
>
>    if(counter == 59) {
>
>       counter = 0;
>
>       return 1;
>
>    }
>
>    counter++;
>
>    return 0;
>
>}
>
>Now to make it hard. You can't use any math operations - no 
>addition, subtraction multiplication or division, including the 
>increment/decrement operations.
>
>Bonus points for using no more static memory than one byte, and code 
>less than 10 lines - with each statement on a line of their own.
>
>Mike
>
>_______________________________________________
>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.
>
>When replying, please edit your Subject line to reflect new content.




More information about the Chchrobotics mailing list