Within the code size limit of only a few kilobytes, contestants have managed to do complicated things – a 2004 winner turned out an
operating system. Modern compilers, benefiting from lessons learned from contest entries, warn users of problematic source code. You may need to suppress warnings to compile contest entries.
Toledo Nanochess Toledo Nanochess is a
chess engine created by Mexican software developer Oscar Toledo Gutiérrez, a five-time winner of the IOCCC. In accordance with IOCCC rules, the original being 1963 characters long. The author claims that it is the world's smallest chess program written in C. The source code for
Toledo Nanochess and other engines is available. Because
Toledo Nanochess is based on Toledo's winning entry from IOCCC18, it is heavily
obfuscated. On February 2, 2014, the author published the book
Toledo Nanochess: The commented source code, which contains the fully commented source code. As of February 7, 2010, it appears to be one of only two chess engines written in less than 2 kilobytes of C that are able to play full legal chess moves, along with
Micro-Max by Dutch physicist H. G. Muller. In 2014 the 1 kilobyte barrier was broken by
Super Micro Chess – a derivative of Micro-Max – totaling 760 characters (spaces and newlines included). There is also a smaller version of Toledo's engine, the
Toledo Picochess, consisting of 944 non-blank characters. typedef char ** C; • define F getchar()) #define H(z)*n++=z; #include #define v pain(0,0,0 #define Z while( #define _ if( • define o(d) (u[l]=0,l[d]=6^e,q=1e4>v,0),l[d]=0,u[l]=e^6,q) • define I(H,n) { _ r=l[x=H],!r|(r^e)x)t=j,i=-7; Z++ix)*(9*O[28+i]-288))+O[r+28\ ]*9-288+O[x%10+33]-f-O[33+u%10]; x[l]=i; S|=(21=\ =u|21==x)*2+(u==28|28==x)*4+(91==u|x==91)*16+32\ • (u==98|x==98)+(20==d)*64*x; a-=k>f?pain(a,f+1\ ,M,k):0; _ i==c&u==h&!f&N&a>-1e4&x==y)longjm\ p(z,1); S=b; _!N|f&&(a>M||!f&a==M&&1&rand()\ )){ _!f){ _ k){ c=i; h=u; y=x; } } else _ \ L-aGK[_`fFDZXEYR" "L\t####" "##B#A#@#G#F#E#D#K\t\3Zlv#tjm" "\3J#tjm\3Pwb" "ofnbwf\3Joofdbo\3)&`&`.&`&`" "#+&g*\t"; G y, c,h,e,S,*s,l[149]; jmp_buf z; G main(G L, C fa, C Na){ return pain(L, fa, Na, kk);} G pain(G L,C fa, C Na, C ka){G f=fa; G N=Na; G k=ka; G u=99,p,q,r,j,i,x ,t, a, b,d,M=-1e9 ; char *n; if( *l){ e=~e; Z u >21){ q= l[--u]^e; _!-- q){ _!l[p=e?u-10:u+10]){ I(p,)_ e?u>80 & !l[p -=10]:u>6){ l[u-1]=0; I(p,l[u-1]=-2^e); } _ l[ p=e?u-9:11+u])I(p,)else _ S>>6==1+u){ l[1+u]=0; I(p,l [1+u]=e^-2); } } _!--q){ n=O+41; Z++nq){ n=q==2?53+O:O+49; Z++nh|98(h+1 )% 10); O[h++]^=3; } n=O +14; s=20+l; Z ++s7){ H(58 -u/10)H(32)_ u&1)puts(n=J); } } puts (O+58); _-1e4 >v , 1)){ e=~e; puts (O+(v,0)> 1e4?e?90:82:96)); break ; } _ 11&&u!=c [O]); c=e^c-7; } } _! setjmp(z)){ v+1,1); puts( 106+ O); } } Z 10!= F; }
Pi Below is a 1988 entry which calculates
Pi by looking at its own
area. This was written in the original
K&R C. Note: The original preprocessor line submitted in 1988 was , which exploited a bug in the K&R preprocessor, corrected before ANSI C89. • define _ F-->00||F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ }
Flight simulator Another example is a
flight simulator using X Windows, the winner of the 1998 IOCCC, as listed and described in
Calculated Bets: Computers, Gambling, and Mathematical Modeling to Win (2001) and shown below: • include • include • include • include double L ,o ,P ,_=dt,T,Z,D=1,d, s[999],E,h= 8,I, J,K,w[999],M,m,O ,n[999],j=33e-3,i= 1E3,r,t, u,v ,W,S= 74.5,l=221,X=7.26, a,B,A=32.2,c, F,H; int N,q, C, y,p,U; Window z; char f[52] ; GC k; main(){ Display*e= XOpenDisplay( 0); z=RootWindow(e,0); for (XSetForeground(e,k=XCreateGC (e,z,0,0),BlackPixel(e,0)) ; scanf("%lf%lf%lf",y +n,w+y, y+s)+1; y ++); XSelectInput(e,z= XCreateSimpleWindow(e,z,0,0,400,400, 0,0,WhitePixel(e,0) ),KeyPressMask); for(XMapWindow(e,z); ; T=sin(O)){ struct timeval G={ 0,dt*1e6} ; K= cos(j); N=1e4; M+= H*_; Z=D*K; F+=_*P; r=E*K; W=cos( O); m=K*W; H=K*T; O+=D*_*F/ K+d/K*E*_; B= sin(j); a=B*T*D-E*W; XClearWindow(e,z); t=T*E+ D*B*W; j+=d*_*D-_*F*E; P=W*E*B-T*D; for (o+=(I=D*W+E • T*B,E*d/K *B+v+B/K*F*D)*_; p K)N=1e4; else{ q=W/K *4E2+2e2; C= 2E2+4e2/ K *D; N-1E4&& XDrawLine(e ,z,k,N ,U,q,C); N=q; U=C; } ++p; } L+=_* (X*t +P*M+m*l); T=X*X+ l*l+M *M; XDrawString(e,z,k ,20,380,f,17); D=v/l*15; i+=(B *l-M*r -X*Z)*_; for(; XPending(e); u *=CS!=N){ XEvent z; XNextEvent(e ,&z); ++*((N=XLookupKeysym (&z.xkey,0))-IT? N-LT? UP-N?& E:& J:& u: &h); --*( DN -N? N-DT ?N== RT?&u: & W:&h:&J ); } m=15*F/l; c+=(I=M/ l,l*H +I*M+a*X)*_; H =A*r+v*X-F*l+( E=.1+X*4.9/l,t =T*m/32-I*T/24 )/S; K=F*M+( h* 1e4/l-(T+ E*5*T*E)/3e2 )/S-X*d-B*A; a=2.63 /l*d; X+=( d*l-T/S *(.19*E +a *.64+J/1e3 )-M* v +A* Z)*_; l += K *_; W=d; sprintf(f, "%5d %3d" "%7d",p =l /1.7,(C=9E3+ O*57.3)%0550,(int)i); d+=T*(.45-14/l* X-a*130-J* .14)*_/125e2+F*_*v; P=(T*(47 *I-m* 52+E*94 *D-t*.38+u*.21*E) /1e2+W* 179*v)/2312; select(p=0,0,0,0,&G); v-=( W*F-T*(.63*m-I*.086+m*E*19-D*25-.11*u )/107e2)*_; D=cos(o); E=sin(o); } }
Akari Below is a 2011 entry which downsamples
PGM,
PPM images and ASCII art (of Akari from
YuruYuri) by Don, Yang: /* + + + + [ >i>n[t */ #include /*2w0,1m2,]_r>i>=>(['0n1'0)1; */int/**/main(int/**/n,char**m){FILE*p,*q;int A,k,a,r,i/* #uinndcelfu_dseti/_*/;char*d="P%" "d\n%d\40%d"/**/ "\n%d\n\00wb+",b[1024],y[]="yuriyurarararayuruyuri*daijiken**akkari~n**" "/y*u*k/riinrarararayuruy9uriyu3riyurar_aBrMaPrOaWy^?" "*]/f]`;hvroai+b+i>++b++>l[rb";int/**/u;for(i=0;i1&&(m[1][0]-'-'||m[1][1] !='\0'))?fopen(m[1],y+298):stdin; /*y/riynrt~(^w^)],]c+h+a+r+*+*[n>)+{>f+oy++>u>>+r >+u+++y>--u---r>++i+++" -m-.>a-.-i.++n.>[(w)*/!q/**/) return+printf("Can " "not\x20open\40%s\40" "" "for\40%sing\n",m[!p?1:2],!p?/* o=82]54>-+(> m- &-1.9-2-)-|-|.28>-w-?-m.:>([28+ */"read":"writ");for ( a=k=u= 0;y[u]; u=2 +u){y[k++ ]=y[u];}if((a=fread(b,1,1024/* ,mY/R*Y"R*/,p/*U*/)/* R*/ )>/*U{ */ 2&& b/*Y*/[0]/*U*/=='P' &&4==/*"y*r/y)r\} • /sscanf(b,d,&k,& A,& i, &r)&& ! (k-6&&k -5)&&r==255){u=A;if(n>3){/* ]&3> +:+ .1>3+++ . -m-) -;.u+=++.1>1,i>>1,r);u = k-5?8:4;k=3;}else /*]>*/{(u)=/*{ p> >u >t>-]s >++(.yryr*/+( n+14>17)?8/4:8*5/ 4;}for(r=i=0 ; ;){u*=6;u+= (n>3?1:0);if (y[u]&01)fputc(/* h.a r -(-).)8+;+i.(([180*/1* (r),q);if(y[u ]&16)k=A;if (y[u]&2)k--;if(i/* ("^w^NAMORI; { I*/==a/*" )*/){/**/i=a=(u)*11 &255;if(1&&0>= (a= fread(b,1,1024,p))&& ")]i>(w)-;} { /i-f-(-m--M1-0.)> *.. If the program is run using its own source as the input, the result is: $ ./akari akari.c int *w,m,_namori=('n'); #include/*;hrd"% dnd4%"*/ /**/int(y),u,r[128*2/*{y}icuhya*rr*rya= */];void/**/i(){putchar(u);}int/**/main(/* "(n"l)?M5{YlcpvdluvKct[j skao(tve"t"oYRYR" */int(w),char**n){for(m =256;--m;r[m]/* "r>u+y-u-r+i+" ) ;>m.a.i+n>()/q*/ =25w?m:(2+ m/*"*,/U// R/)/U * & /Y/0/U/=P &=/"*/)\ &16?m-13 : 13+ m) ;u=+10 ;for(;(m=/* *>/()/{ p u t-s +(yy*+ n1>7?/:*/ getchar ())+1 ;i() ){if(10/* "wNMR;{ I/=/" )/{*/==u*1 )i(); if(m-10){ u=/*> *./ ./akari.small $ ./akari ./akari.small wm_aoi(n) /*ity,,[2*/{}char*y= (")M{lpduKtjsa(v""YY" "*yuruyuri") ;main(/* /",U/ R)U* Y0U= ="/\ • /){puts (y+ 17/* "NR{I=" ){/=* =* */);/* **/{ ;;}} $ $ ./akari ./akari.small > ./akari.smaller $ ./akari ./akari.smaller main (){puts("Y" "U RU YU "\ "RI" )/* */ ;} $ ==See also==