* quad <quadricode@gmail.com> [Jul 18. 2011 18:28]:
main(c,r){for(r=32;r;)printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
Cheers!
-Robert
Here is some non-obfuscated code doing a mildly more nontrivial thing (ulong shall be some unsigned integer type): ------------------------------- bool bit_paper_fold(ulong k) // Return element number k of the paper-folding sequence: // k= 0, 1, 2, 3, 4, 5, ... // seq(k)= 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, ... // Sequence (for k>=1) is entry A014577 of the OEIS. // Also: for k>=1, the dragon curve turns left if seq(k)=1, else right. // Also fixed point of morphism (for k>0, identify + with 1 and - with 0) // L |--> L+R+L-R, R |--> L+R-L-R, + |--> +, - |--> - { ulong h = k & -k; k &= (h<<1); return ( k==0 ); } ------------------------------- Two renderings of the curve on p.89 of the friendly fxtbook. A generalization is: ------------------------------- bool bit_paper_fold_general(ulong k, ulong w) // Return element number k of the general paper-folding sequence: // bit number x of the words w determines whether // a left or right fold is made at the step x. // With w==0 the result is ! bit_paper_fold(k). { ulong h = k & -k; // == lowest_one(k) h <<= 1; ulong t = h & (k^w); return ( t!=0 ); } ------------------------------- Rendering with control word (binary) ....1010101010 gives a triangular shaped variant of the paperfold curve (see p.91). Terdragon curve, just for the kicks (p.93): ------------------------------- bool bit_dragon3_turn(ulong &x) // Increment the radix-3 word x and // return (tr) whether the number of ones in x is decreased. // tr determines whether to turn left or right (by 120 degrees) // with the terdragon fractal. // // Starting with x==0: // x tr // ........ 0 // .......1 0 // ......1. 1 // .....1.. 0 // .....1.1 0 // .....11. 1 // ....1... 1 // ....1..1 0 // ....1.1. 1 // ...1.... 0 // The sequence tr (for x>=1) is entry A080846 in the OEIS, // the fixed point of the morphism 0 |--> 010, 1 |--> 011. // See also A060236 (== 1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2, ...). // Also fixed point of morphism (for k>0, identify + with 0 and - with 1) // F |--> F+F-F, + |--> +, - |--> - { ulong s = 0; while ( (x & 3) == 2 ) { x >>= 2; ++s; } // scan over nines // if ( (x & 3) == 0 ) ==> incremented word will have one more 1 // if ( (x & 3) == 1 ) ==> incremented word will have one less 1 bool tr = ( (x & 3) != 0 ); // incremented word will have one less 1 ++x; // increment next digit x <<= (s<<1); // shift back return tr; } ------------------------------- Jawohl!