Page 1 of 2 12 LastLast
Results 1 to 25 of 32
  1. #1
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    Can you guys help me optimize this? The entire project is centered around this piece of software I have been designing for a couple of months now:

    Code:
    // File: evenodd.c
    // To compile: gcc -std=c99 -O3 -fomit-frame-pointer -fstrength-reduce -o evenodd.o -c evenodd.c
    
    #include "evenodd.h"
    #include <stdbool.h>
    
    // is x odd?
    bool is_odd(int);
    
    
    // assumes x >= 0
    bool is_even(int n)
    {
      if (n == 1) return false;
      else return is_odd(n-1);
    }
    
    bool is_odd(int n)
    {
       return (n == 1)? true : is_even(n-1);
    }
    Any help would be appreciated.

  2. #2
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473

  3. #3
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    What are you laughing at? You know how many people strive for O(n) perforamnce in their algorithms?

  4. #4
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    #define is_odd(a) ((a) & 1)
    #define is_even(a) !is_odd(a)

  5. #5
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    #define is_odd(a) ((a) & 1)
    #define is_even(a) !is_odd(a)
    No type checking.

    Unacceptable. s think I'm scheming or some ?

  6. #6
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    i've been writing csharp code lately and damn do I miss macros...

    It's also re ed that nullable types are also not boolean...

    object a = null;

    if (a) <--- Error!!! You gotta do 'if (a != null)'
    {
    // blah
    }

  7. #7
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    Also, can you believe Win8 Metro doesn't have standard date/time pickers or a calendar control?

    XAML is also this Frankenstein construction you get the feeling was thought out by an amateur in some Indian backroom.

    Which is amazing considering it's from the same people that wrote Intellisense for Visual Studio which is pretty much the .

  8. #8
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    Another gem: no built in support for timezones... you either work on 'local' time or UTC time...

    I can't tell you how much I had to write on top of the actual project. And still have a long ways to go.

  9. #9
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    i've been writing csharp code lately and damn do I miss macros...

    It's also re ed that nullable types are also not boolean...

    object a = null;

    if (a) <--- Error!!! You gotta do 'if (a != null)'
    {
    // blah
    }
    Did you used to work at my company? This is a piece of legacy code that I got tasked with maintenance on.

    Code:
    // File: app.c
    // To compile: gcc -O3 -fomit-frame-pointer -o app app.c
    
    #include "stdio.h"
    #define	e 3
    #define	g (e/e)
    #define	h ((g+e)/2)
    #define	f (e-g-h)
    #define	j (e*e-g)
    #define k (j-h)
    #define	l(x) tab2[x]/h
    #define	m(n,a) ((n&(a))==(a))
    
    long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
    int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
    
    main(m1,s) char *s; {
      int a,b,c,d,o[k],n=(int)s;
      if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
      else switch(m1-=h){
      case f:
        a=(b=(c=(d=g)<<g)<<g)<<g;
        return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
      case h:
        for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
      case g:
        if(n<h)return(g);
        if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
        else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
        if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
        return(o[b-g]%n+k-h);
      default:
        if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
        for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
      }
    }

  10. #10
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    lol o Word... those obfuscated codes are too much, tbh

  11. #11
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    Code:
                              #define  \
                            D(s)"<<"#s">>"
                          #define  q(s)p(#s)
                         #define S " endobj "
                        #define Y "endstream"S
                        #include     <stdio.h>
                        #define  o(s) b[s]=_;\
                         p("%u    0  obj",s);
    #define E for         (c=d;c  < 123;c++)
      #define DANCE         "trailer   "D\
        (/Root 3 0            R /Size %d)            "\nstartxref %u %%%%EOF\n*/"
          #define              p(s, ...)             _+=printf(s,  ##__VA_ARGS__)
           #define C         "<</Type/Page         /Parent %d %d R /Resources <<\
            /ProcSet[       /PDF/Text]/Font       <</U"D(/Subtype/Type1/BaseFont\
              /Courier) "  /T<</Subtype/Type3   /FontBBox[0 0 10 10]/FontMatrix[\
               %f 0 0 %f 0 0]/FirstChar %d/LastChar %d/Encoding<</Differences[%d"
                typedef int N;typedef char*Nyan;typedef char A;N a,b[64],d=65,_,v
                  [32]={84,0,64,282,90,74,330,85,93,173,167,176,80,208,81,13,7,87
                    ,160,346,32,128,170,218,16,26}; Nyan w[]={"+*-(,&-&","+*,&-&"
                      ,"+*.&/&","+*/*/+","+*())'('"  ,"+**&)&","+*(&'&","+*'*'+",
                        "","+,./","+,-,./","+--,+*"  ,"","+,(/","+,),(/","+-),+*"
                         ,"10 0 d0 ","8 7 2 2 re "   ,"+*+.'`'@'mi +/+/(mi"};Nyan
                           nyan(Nyan _,N y,A n){
                            N g=v[~-y%32];Nyan
                             s=w[g>>n&3|n*2];
                             for(a=0;*_=*s++;
                             a++,_++,*_++=32)
                             {*_+=*_-32?10:0;
                             if(a%2&&*_/16==3
                             ){if(g>>8)*_=105-*_;
                            _++;*_++=32;*_=~-a&&a-13
                            ?108:109;}}return n?n-9?nyan
                           (_,y,n-2):_:nyan(_+=~y&' '?sprintf
                          (_,17[w]):0,y,9);}N main(N c){A e[256];
                         p("/*%%PDF-1.3%%*/")-2;q(#include<stdio.h>\n);
                        q(#define o *_++&& *_-41\n#define);p(" endstream ");q
                       (main(){for(;*_++;      *_-40?:putchar(o?*_:o?10:41));\n)
                      ;q(#define  endobj          return 0;}\n);q(typedef int ET;/)
                     ;q(*);o(1)*b=~(p(D                 (/Length 2 0 R)"stream\n"))
                    ;for(p("BT 12 818"                    " Td/%c 12 Tf 12 TL%%%c/"
                   "static char*_=\""                       " \\\n",7[v],*v/2);c=
                  getchar(),~c;c-10?                         p("/%c 12 Tf(\\%o)"
                 "Tj",v[~-c%' '<25[                         v]&&!~-(~-c/'@')?0
                :7],c):(p("()'")))                         ;p("%%\";\nET ");*
               b-=~_;p(Y"/*");E{a                         =nyan(e+sprintf(e,
              16[w]),c,6)-e;o(c-                         59)p(D(/Length %d)
             "stream\n%s"Y,a,e)                         ;}o(2)p(" %u"S,*b);
            o(3)p(D(/Pages 4 0                         R)S);o(4)p(D(/Count
           1/MediaBox[0 0 595                         842]/Kids[5 0 R])S)
          ;o(5)p(C,4,0,6e-2,                         6e-2f,d,122,d);E p(
         "/%c",~-c/6+~14?c:                         d);q(]>>/CharProcs<<)
        ;E if(~-c/6+~14)p(                           "/%c %d 0 R",c,c+~58);
       for(q(>>/Widths[),                             c=59;--c;p(" 10"));a=p
      ("]>>>>>>/Contents 1                              0 R>>"S);for(p("xref\
     0 %d ",--d);c<d;p("%010u\
     %05d n  ",*(c+++b),NULL));
      return!(p(DANCE,d,a));}

  12. #12
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    Oh my god, the output of that dancing man program given that o world as input


  13. #13
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    it says you can compile the PDF with gcc and it works too

  14. #14
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    it says you can compile the PDF with gcc and it works too
    gcc made me rename it to a .c file and then its output was the original c file: say the dancing program is named dance

    Code:
    parker@lolmexico:~/Desktop$ ./dance <app.c >app.pdf
    parker@lolmexico:~/Desktop$ cp app.pdf foo.c
    parker@lolmexico:~/Desktop$ gcc foo.c
    parker@lolmexico:~/Desktop$ ./a.out
    // File: app.c
    // To compile: gcc -O3 -fomit-frame-pointer -o app app.c
    
    #include "stdio.h"
    #define	e 3
    #define	g (e/e)
    #define	h ((g+e)/2)
    #define	f (e-g-h)
    #define	j (e*e-g)
    #define k (j-h)
    #define	l(x) tab2[x]/h
    #define	m(n,a) ((n&(a))==(a))
    
    long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
    int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
    
    main(m1,s) char *s; {
      int a,b,c,d,o[k],n=(int)s;
      if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
      else switch(m1-=h){
      case f:
        a=(b=(c=(d=g)<<g)<<g)<<g;
        return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
      case h:
        for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
      case g:
        if(n<h)return(g);
        if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
        else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
        if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
        return(o[b-g]%n+k-h);
      default:
        if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
        for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
      }
    }parker@lolmexico:~/Desktop$

  15. #15
    🏆🏆🏆🏆🏆 ElNono's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Apr 2007
    Post Count
    153,473
    thats pretty cool

  16. #16
    e^(i*pi) + 1 = 0 MannyIsGod's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    57,943
    ing nerds.

  17. #17
    e^(i*pi) + 1 = 0 MannyIsGod's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    57,943
    I'm ing happy if I can actually get matlab to run my simple scripts.

  18. #18
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    It was approved for our library, as my function cut the stack depth from O(n^2) (prev version) to O(n) while still maintaining fast O(n) timing.

  19. #19
    Spur-taaaa TDMVPDPOY's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Feb 2005
    Post Count
    41,384
    surprise u clowns still in the programming business...

  20. #20
    Veteran DarrinS's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Jun 2005
    Post Count
    42,561
    Also, can you believe Win8 Metro doesn't have standard date/time pickers or a calendar control?

    XAML is also this Frankenstein construction you get the feeling was thought out by an amateur in some Indian backroom.

    Which is amazing considering it's from the same people that wrote Intellisense for Visual Studio which is pretty much the .


    XAML is pretty much a ripoff of SVG. Just as C# is just a ripoff of Java. Or maybe just heavily influenced.

    With Win8, I really can't tell where MS is headed with their development platform.

  21. #21
    Veteran DarrinS's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Jun 2005
    Post Count
    42,561
    I'm ing happy if I can actually get matlab to run my simple scripts.
    I love Matlab. Been using it since late 1980's. I'm on ver R2012b now.
    Last edited by DarrinS; 04-23-2013 at 09:45 AM.

  22. #22
    Veteran DarrinS's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Jun 2005
    Post Count
    42,561
    i've been writing csharp code lately and damn do I miss macros...

    It's also re ed that nullable types are also not boolean...

    object a = null;

    if (a) <--- Error!!! You gotta do 'if (a != null)'
    {
    // blah
    }

    Some parts of the language are pretty dumb, but I have to admit, it is very readable. Also, LINQ is very powerful.

  23. #23
    e^(i*pi) + 1 = 0 MannyIsGod's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    57,943
    I love Matlab. Been using it since late 1980's. I'm on ver R2012b now.
    I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.

  24. #24
    Veteran DarrinS's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Jun 2005
    Post Count
    42,561
    I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.
    They also have a very good user community -- very friendly and willing to answer all types of technical questions.

  25. #25
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    I love it too. I just am terrible at writing scripts to get what I want done. Its probably just a practice/familiarity thing so hopefully I will get better over time.
    You ever seen OCW's quick Matlab course, Manny?

    http://ocw.mit.edu/courses/electrica...uary-iap-2010/

    Pretty cool , especially the assignment on plotting the Mandelbrot set. There is another one that looks like a more full course:

    http://ocw.mit.edu/courses/mathemati...ing-fall-2011/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •