Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Any reason to use C?

Author: Dann Corbit

Date: 14:10:47 07/29/03

Go up one level in this thread


On July 29, 2003 at 16:52:43, Tord Romstad wrote:

>On July 29, 2003 at 15:40:50, Dieter Buerssner wrote:
>
>>On July 29, 2003 at 15:31:11, Tord Romstad wrote:
>>
>>>This is getting increasingly off-topic, but I cannot resist the temptation
>>>to post the cutest little C program I have ever seen.  It computes an
>>>approximation of pi by calculating its own area.  :-)
>>
>>I know that program. Really amazing. And very clever. One can even understand
>>it after a while.
>
>Yes, one can understand how it works, but I never understood how people get
>such ideas.  It is of course an entirely useless skill (much like programming
>chess), but I still wish I could do it.
>
>>On www.iocc.org, one can even find chess related programs.
>
>Thanks to you and Dann for this link!  I have seen several of the programs
>before, but the Web site was new and unknown to me.

I have entered the contest, but my entries have never been good enough to win.

My 1998 attempt does numerical integrations:

#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#define Z isalpha
#define I isupper
#define A atoi
#define F atof
#define b if
#define c char
#define d double
#define e else
#define g exit
#define j int
#define m main
#define p printf
#define r return
#define t typedef
#define w while
#define v void
j x(j f){c B='a';b(Z(f)){b(I(f))B='A';f=(f-B+13)%26+B;}r f;}c*X(c*s){j i
;for(i=0;i<(j)strlen(s);i++)s[i]=(c)x(s[i]);r s;}c*cc="Guvf cebtenz qbr\
f ahzrevp vagrtengvba.\nHfntr: %f <shapgvba ahzore> <fgneg> <raq>\n\tju\
rer <shapgvba ahzore> jvyy or vagrecergrq nf sbyybjf:\n\t0 Qrevingvir b\
s ybtnevguz(1/k)\n\t1 Angheny ybtnevguz bs k\n\t2 Ybtnevguz onfr 10 bs \
k\n\t3 Fdhner ebbg bs k\n\t4 Qrevingvir bs reebe shapgvba bs k\n\t5 Pbf\
var bs k\n\t6 Ulcreobyvp pbfvar bs k\n\t7 Rkcbaragvny bs k\n\t8 Fvar bs\
 k\n\t9 Ulcreobyvp fvar bs k\n\t10 Gnatrag bs k\n\t11 Ulcreobyvp gnatra\
g bs k\n\tnaq <fgneg> <raq> ner fgneg naq raq cbvagf sbe vagrtengvba.\n"
;t d(*f_t)(d);v q(c*s,c*S){p(X(cc),S);p(X(s));g(0);}d derf(d y){if(y==0.
)r 1.;e r exp(-y*y);}d dlog(d y){r 1./y;}j k;j fmf(f_t f[]){w(f[k])k++;r
--k;}d i(d a,d l,f_t f){d H=(l-a)*.1;b(H>.01){d M=a+(l-a)*.5;r i(a,M,f)+
i(M,l,f);}e{r(16067*(f(a)+f(a+H*10))+106300*(f(a+H)+f(a+H*9))-48525*(f(a
+H*2)+f(a+H*8))+272400*(f(a+H*3)+f(a+H*7))-260550*(f(a+H*4)+f(a+H*6))+
427368*f(a+H*5))*H*5./299376;}}j m(j ac,c**av){f_t f[]={dlog,log,log10,
sqrt,derf,cos,cosh,exp,sin,sinh,tan,tanh,0};j fc=0;d s=1;d u=2;b(ac>1){
fc=A(av[1]);b(fc<0||fc>fmf(f))q("{vyyrtny shapgvba ahzore}\n",*av);}b(ac
>3){s=F(av[2]);u=F(av[3]);b(u<s)q("{raq orsber fgneg}\n",*av);b(fc<4&&s
<=0)q("{qbznva reebe}\n",*av);}p("%f\n",i(s,u,f[fc]));r 0;}

My entry for 2000 was a unique wordlist program:

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<limits.h>
#include<ctype.h>
typedef unsigned long u;typedef int i;typedef void v;typedef char Z;
#define T 30000
#define f if
#define e else
#define g for
#define o return
#define q static
#define st strlen
#define sc strcpy
#define ma malloc
#define wh while
#define fr free
#define a w[
#define M(x,y)(strcmp(x,y))
#define K(x,y)(M(x,y)<0)
#define L(x,y)(M(x,y)==0)
q Z*a 10*T];q Z*x[10*T];v sr(u c){u m;i j,p;Z*t;g(p=c;p>0;){g(m=p;m<c;m
++){j=m;t=a m];wh(j>=p&&(K(t,a j-p]))){a j]=a j-p];j-=p;}a j]=t;}p=((p>1
)&&(p<5))?1:5*p/11;}}u sh(v){u j,m=0;Z*a0="";Z*a1=a 0];g(j=0;a j];j++){
a1=a j];f(!L(a1,a0)){Z*p;p=ma(st(a1)+1);f(p){sc(p,a1);x[m++]=p;}e{exit(0
);}a0=a1;}}g(j=0;a j];j++){fr(a j]);a j]=0;}g(j=0;x[j];j++){a j]=x[j];x[
j]=0;}o m;}q Z sp[UCHAR_MAX];q Z z[T];i main(v){i m;i j=0;u c=0;Z*t;g(m=
1;m<UCHAR_MAX;m++)f(!isalpha(m)&&m!='-'&&m!='\'')sp[j++]=(Z)m;wh(fgets(z
,T,stdin)){t=strtok(z,sp);wh(t){Z*k;k=ma(st(t)+1);f(k){sc(k,t);a c++]=k;
}e{exit(0);}t=strtok(0,sp);}f(c>T){sr(c);c=sh();}}sr(c);c=sh();g(m=0;a m
];m++){puts(a m]);fr(a m]);}o 0;}




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.