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:
Any help would be appreciated.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); }
What are you laughing at? You know how many people strive for O(n) perforamnce in their algorithms?
#define is_odd(a) ((a) & 1)
#define is_even(a) !is_odd(a)
No type checking.
Unacceptable. s think I'm scheming or some ?
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
}
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 .
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.
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); } }
lol o Word... those obfuscated codes are too much, tbh![]()
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));}![]()
Oh my god, the output of that dancing man program given that o world as input
![]()
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$
I'm ing happy if I can actually get matlab to run my simple scripts.
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.
surprise u clowns still in the programming business...
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.
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.
Some parts of the language are pretty dumb, but I have to admit, it is very readable. Also, LINQ is very powerful.
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.
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/
There are currently 1 users browsing this thread. (0 members and 1 guests)