Below are two C programs: PROGRAM 1 calling Gen2_Gray, and PROGRAM 2 calling Update_Perm. ############################################ PROGRAM 1 It outputs * only 'pertinent' suffixes, that are suffixes c_{p-2}c_{p-1}c_p ... c_n with p the rightmost position where the currrent composition differs from the previous one, * p, and * u=c1+c_2c+ ... c_p. #include int c[20],n,N=0; type(int p,int v) {int i; printf("%d\t",N++); for(i=1;i<=n;i++) if(p-i<3) printf("%d ",c[i]); else printf(". "); printf(" %d %d\n",p,v); if(N%20==0) getchar(); } int comp_ell( int u) { int i=1; while ( i*(i-1)/2 =3 && k==(r*(r-1))/2 ) type(p,u); else { ell=comp_ell(k); e=k-( (ell-1)*(ell-2) /2); if (dir%2==0) { c[ell]=c[ell]+e; Gen2_Gray(k-e,ell,0,p,u);c[ell]=c[ell]-e; d=(r-ell)%2; for (i=ell+1;i<=r;i++) { c[i]++; Gen2_Gray(k-1,i,d,i,k-1+c[i]);d++;c[i]--; } } else { d=0; for (i=r;i>=ell+1;i--) { if(i==r) {q=p; v=u;} else {q=i+1;v=c[i+1]+k;} c[i]++; Gen2_Gray(k-1,i,d,q,v);d++;c[i]--; } if(ell==r) {q=p; v=u;} else {q=ell+1;v=c[ell+1]+k;} c[ell]=c[ell]+e; Gen2_Gray(k-e,ell,1,q,v);d++;c[ell]=c[ell]-e; } } } main() { int i,k; double fff; printf("give n:");scanf("%d",&n); printf("give k:");scanf("%d",&k); for(i=1;i<=n;i++) c[i]=0; Gen2_Gray(k,n,0,0,k); } ############################################ PROGRAM 2 #include int n, sigma[20], s[20], c[20]; int comp_ell( int u) { int i=1; while ( i*(i-1)/2 = 1 && s[p-2]==c[p-2] ) f=p-1; else {f=p-2; x=x-c[f];} a1=s[f]-c[f]; a2=s[f+1]-c[f+1]; if( (f+2)> n) a3=0; else a3= s[f+2]-c[f+2]; if(a1>0) v=1; else v=-1; if(a1==1 && a2==-1 && a3==0 || a1==-1 && a2==1 && a3==0 ) transp(v, f, x); if(a1==2 && a2==-2 && a3==0 || a1==-2 && a2==2 && a3==0 ) { transp(v, f, x); transp(v, f, x);} if(a1==1 && a2==-2 && a3==1 || a1==-1 && a2==2 && a3==-1 ) { transp(v, f, x); transp(-v, f+1, x+s[f]);} if(a1==1 && a2==-3 && a3==2 || a1==-1 && a2==3 && a3==-2 ) { transp(v, f, x); transp(-v, f+1, x+s[f]); transp(-v, f+1, x+s[f]);} if(a1==1 && a2==1 && a3==-2 || a1==-1 && a2==-1 && a3==2 ) { transp(v, f+1, x+s[f]); transp(v, f, x); transp(v, f+1, x+s[f]);} if(a1==1 && a2==0 && a3==-1 ) { transp(1, f, x); transp(1, f+1, x+s[f]);} if(a1==-1 && a2==0 && a3==1 ) { transp(-1, f+1, x+s[f]); transp(-1, f, x);} } main() { int i,p,u; printf("give n:");scanf("%d",&n); printf("give a composition s:\n"); for(i=1;i<=n;i++) { printf("s[%d]=",i);scanf("%d",&s[i]);} printf("give a the next composition:\n"); for(i=1;i<=n;i++) { printf("c[%d]=",i);scanf("%d",&c[i]);} printf("give the permutation sigma corresponding to s:\n"); for(i=1;i<=n;i++) { printf("sigma[%d]=",i);scanf("%d",&sigma[i]);} printf("give the the rightmost position p where s differ from c:\n"); scanf("%d",&p); printf("give u=c1+c2+...+cp:\n"); scanf("%d",&u); Update_Perm(p, u); printf("s becomes:\n"); for(i=1;i<=n;i++) printf("%d",s[i]); printf("\n"); printf("sigma becomes:\n"); for(i=1;i<=n;i++) printf("%d",sigma[i]); printf("\n"); }