@*Intro. This program generates all Kepler towers made from $n$ bricks. (It supplements the old program {\mc VIENNOT} in my Mittag-Leffler report ``Three Catalan bijections,'' which was incomplete: The claim that all towers are generated was never proved, because I'd blithely assumed that there are no more than $C_n$ of them.) @d maxn 40 /* this is plenty big, since $C_{40}>10^{21}$ */ @c #include #include int n; /* command line parameter */ int x[maxn]; /* current brick position */ int w[maxn]; /* current wall number */ int p[maxn]; /* beginning of supporting layer */ int q[maxn]; /* beginning of current layer */ int t[maxn]; /* type of move: 1 if end of layer, 2 if end of wall */ char punct[3]={',',';',':'}; /* separators */ unsigned long long count; /* this many found */ main (int argc,char*argv[]) { register i,j,k,l,mask; @; b1: @; b2:@+if (l>n) @; w[l]=w[l-1]; switch (t[l-1]) { case 0: x[l]=x[l-1]+2; /* add brick to the current layer */ if (x[l]>(1<; b4:@+@; b5:@+if (--l) { if (p[l]==0 && t[l]!=1) goto b5; /* we're backtracking to previous wall */ goto b4; } fprintf(stderr,"Altogether %lld towers generated.\n", count); } @ @= if (argc!=2 || sscanf(argv[1],"%d", &n)!=1) { fprintf(stderr,"Usage: %s n\n", argv[0]); exit(-1); } if (n>maxn) { fprintf(stderr,"You must be kidding; I can't handle n>%d!\n", maxn); exit(-2); } @ @= { count++; if (n<=10) for (j=1;j<=n;j++) printf("%d%c", x[j], j= l=0,t[0]=1; goto b4; @ @= if (t[l-1]) q[l]=l,p[l]=q[l-1]; else q[l]=q[l-1],p[l]=p[l-1]; if (x[l]==(1<= switch (t[l]) { case 0: t[l++]=1; /* initiate a new layer */ goto b2; case 1:@+if (l+(1<

AltStyle によって変換されたページ (->オリジナル) /