??? 06/10/07 14:37 Modified: 06/10/07 15:53 Read: times |
#140507 - Very nice, but call it 43 (explained herein) Responding to: ???'s previous message |
Michael said:
#define R return #define W while UC TestFlip(UC c) { UC r,i=8;W(i--){r>>=1;r|=c&128;c*=2;}R r; } Ooh! Very nice, even if you did play sort of fast and loose with the #defines. (c: Carried to the extreme, that idea could reduce any solution to one byte: #define K UC r,i=8;while(i--){r>>=1;r|=c&128;c*=2;}return r; UC TestFlip(UC c) { K // 1 byte!!! }Seriously, though, your solution does expose the first "kink" that needs to be wrung out of the contest. And that is, it seems wrong to bias the contest in favor of certain language features because of the arbitrary spelling of the corresponding keywords. To fix that problem, I'll define a standard set of abbreviations for the C keywords, much as you did for 'while' and 'return'. In order to keep the abbreviations unique while still preserving some mnemonic value, they'll have to be two-characters each. (For example, we can't have 'C' meaning both 'case' and 'continue'.) With these definitions in place, your solution will become: UC TestFlip(UC c) { UC r,i=8;WH(i--){r>>=1;r|=c&128;c*=2;}RT r; }weighing in at 43 bytes. -- Russ PS: There is a very easy way to trim another byte from your solution. You surely would have seen it already had you not been working on this crazy problem in the middle of the night! PPS: Here's the best I had done before your solution came along. I was of course trying to avoid the then-expensive 'while'. But your solution still beats it by a byte or two, even if you do spell out 'while' and 'return'. c=c/2&85|c*2&170;c=c/4&51|c*4&204;return c>>4|c<<4; |