Obfuscated ellipses



  • This isn't a true WTF since I did this on purpose:

    #define _ int
    #define d(c,D,R,Z,F)x,S=1,B=0,O=0,r=1,M=p+E,Q=k,*N=j+f*k,*o=N;p-=E;while(I>=0){x=S<B;c;if(r){if(-1<k&k<u)Z(N,k)if(-1<Q&Q<u)Z(o,Q)F 0;}if(x)++p,--M,S+=I-=D;else k++,Q--,N+=f,o-=f,B+=O+=R,F 1;}}
    #define Y(W,k)0<=p&p<f&&(W[p]=s),0<=M&M<f&&(W[M]=s);
    #define g(W,R,C){_ w=0,C I=E*W,d(r=x==w|!r;w=x,W,R,Y,)
    #define v(W,k){G=p<0?W:W+p;Z=f>M?W+M:W+f;while(G<Z)*G++=s;}
    #define L(W,R,C){_*G,C*Z,I=E*W,d(,W,R,v,r=)
    #define R(n)_ n(_*j,_ f,_ u,_ s,_ p,_ k,_ E,_ e)
    #define a D=e*e,T=E*E,
    R(cr)g(1,1,)R(ov)g(D,T,a)R(fc)L(1,1,)R(fo)L(D,T,a)
    </pre>
    

    This defines 4 functions, which can be prototyped as:

    /* Draw a circle to a 32bpp bitmap, clipping to the edges */
    extern void cr(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int rad);
    
    /* The same, except it fills the circle. */
    extern void fc(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int rad);
    
    /* Draws an ellipse. */
    extern void ov(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int xrad, int yrad);
    
    /* Fills an ellipse. */
    extern void fo(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int xrad, int yrad);
    

    Not only does the code take only 542 bytes (with UNIX newlines), it uses only addition and subtraction operations, except for one multiply to find the initial position in the bitmap, and two multiplications to square the x and y radius in the ellipse functions.



  • Sorry...

    #define _ int
    #define d(c,D,R,Z,F)x,S=1,B=0,O=0,r=1,M=p+E,Q=k,*N=j+f*k,*o=N;p-=E;while(I>=0){x=S<B;c;if(r){if(-1<k&k<u)Z(N,k)if(-1<Q&Q<u)Z(o,Q)F 0;}if(x)++p,--M,S+=I-=D;else k++,Q--,N+=f,o-=f,B+=O+=R,F 1;}}
    #define Y(W,k)0<=p&p<f&&(W[p]=s),0<=M&M<f&&(W[M]=s);
    #define g(W,R,C){_ w=0,C I=E*W,d(r=x==w|!r;w=x,W,R,Y,)
    #define v(W,k){G=p<0?W:W+p;Z=f>M?W+M:W+f;while(G<Z)*G++=s;}
    #define L(W,R,C){_*G,C*Z,I=E*W,d(,W,R,v,r=)
    #define R(n)_ n(_*j,_ f,_ u,_ s,_ p,_ k,_ E,_ e)
    #define a D=e*e,T=E*E,
    R(cr)g(1,1,)R(ov)g(D,T,a)R(fc)L(1,1,)R(fo)L(D,T,a)
    

    This defines 4 functions, which can be prototyped as:

    /* Draw a circle to a 32bpp bitmap, clipping to the edges */
    extern void cr(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int rad);
    
    /* The same, except it fills the circle. */
    extern void fc(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int rad);
    
    /* Draws an ellipse. */
    extern void ov(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int xrad, int yrad);
    
    /* Fills an ellipse. */
    extern void fo(unsigned int* pixels, int w, int h, unsigned int color, int x, int y, int xrad, int yrad);
    

    Not only does the code take only 542 bytes (with UNIX newlines), it uses only addition and subtraction operations, except for one multiply to find the initial position in the bitmap, and two multiplications to square the x and y radius in the ellipse functions.



  • So tell me, with all those defines, what happens to:

    for(int a=0;a<10;a++)

    if you ever use it in your code?????? 

    Do you really think you've done something good by compacting your source code to 542 bytes?  What does hard disk space cost these days?  If that code blindsided me some day during maintenance, it would most likely get deleted and replaced with the expanded version of the code.  There would also be one programmer off my christmas card list that year.



  • I did this just for fun, just to see how small I could make it. This is NOT something I would ever include in "production" code.

    So tell me, with all those defines, what happens to:

    for(int a=0;a<10;a++)

    if you ever use it in your code??????

    It's intended to be compiled as a seperate translation unit, so the defines do not apply to other translation units. Alternatively, it could be copy-pasted at the end of another C file where the defines wouldn't clobber anything before it.



  • "Small" would be in the compiled size; the source size makes no difference whatsoever.  There's no efficiency long-term in doing anything like this, even "for fun."  It's just bad practice.  And applying the word "small" to it is semantically invalid.

    Whoopee.  You want people to be impressed around here, write an O(1) search algorithm.



  • @mrprogguy said:

    "Small" would be in the compiled size; the source size makes no difference whatsoever.  There's no efficiency long-term in doing anything like this, even "for fun."  It's just bad practice.  And applying the word "small" to it is semantically invalid.


    No, it could be useful as part of an ioccc program submission.



  • @mrprogguy said:

    Whoopee.  You want people to be impressed around here, write an O(1) search algorithm.

    //Takes an integer value to search for and an array of integers and returns the index of the first instance of the integer.  Assumes myArray is at most an array of size 2.

    int find (int a, int* myArray)
    {
       if myArray[0]  = a
          return 0;
       else
          return 1;
       end if
    }
     

    Ok, where's my prize?



  • @SeekerDarksteel said:

    Ok, where's my prize?

    Your prize is the content of myArray[2].



  • @mrprogguy said:

    "Small" would be in the compiled size; the source size makes no difference whatsoever.  There's no efficiency long-term in doing anything like this, even "for fun."  It's just bad practice.  And applying the word "small" to it is semantically invalid.

    Whoopee.  You want people to be impressed around here, write an O(1) search algorithm.



    Please, you consider yourself a programmer yet have obvisouly never heard of the Obfuscated C Contest?! Of course this kind of programming is a big no-no for production code. Of course source size is a meaningsless measure of program excellence. Yet obfuscation is a classical and traditional test of C programmers mettle; any good programmer can produce clean, aesthetic, functional code, but writing good, aesthetic obfuscated code, that is an art form! Obfuscated code is NOT intended for live use. Now stop jumping the humourlessness gun when someone is offering a cup of programming humour.


  • @R.Flowers said:

    @SeekerDarksteel said:

    Ok, where's my prize?

    Your prize is the content of myArray[2].

     

    Yaaaay!  *Hugs his fluffy new '\0' and skips off like a little schoolgirl*

     


Log in to reply