??? 06/11/07 15:09 Modified: 06/11/07 16:57 Read: times |
#140551 - Wow is right!!! plus another 36 Responding to: ???'s previous message |
You guys are pretty clever! I thought at first that this problem was too simple and wouldn't lend itself to crazy tricks. Boy, was I wrong. I think this will really be interesting when we try it with a slightly more open-ended problem.
Here's another 36-byte solution that goes down a little bit different path by getting rid of the loop counter and using instead a 16-bit variable to both accumulate the result and stop the loop. It seemed like a good idea at the time, but I don't yet see a way to get rid of that nasty '256'. -- Russ UC TestFlip(UC c) { //c=c/2&85|c*2&170;c=c/4&51|c*4&204;RT c>>4|c<<4; // (47) Cooper //UC r,i=8;WH(i--){r>>=1;r|=c&128;c*=2;}RT r; // (43) Karas //UC r,i=8;WH(i--){r*=2;r|=c&1;c/=2;}RT r; // (40) Karas //UC r,i=8;WH(i--){r=r*2|c&1;c/=2;}RT r; // (38) Cooper //UC r,i=8;WH(i--)r=r*2|c&1,c/=2;RT r; // (36) Kelly //UC r,i=1;WH(r+=c&i?r++:r,i+=i);RT r; // (36) Waclawek //UC r,i=1;WH(r+=r+c/i%2,i+=i);RT r; // (34) Kelly IN r=1;WH(r<256)r=r*2|c&1,c/=2;RT r; // (36) Cooper } |