#include #include #define SIZE 15000 #define BASE 10 typedef enum boolean { FALSE, TRUE } Boolean; void initial(); void write(); void sort(); void reverse(); void add(); int test(); int a[SIZE+1], b[SIZE+1]; int d[BASE+1], p[BASE+1]; int i,n,m,c; int r,s,t,u,v; int length,iter; FILE *outf; void main() { outf=fopen("rats12.out","w"); d[1]=1; d[2]=2; printf("Input limits on p[1] and p[2] and limit\n"); scanf("%d %d %d %d %d",&r,&s,&t,&u,&v); printf("Input iteration size and length\n"); scanf("%d %d",&iter,&length); for(p[1]=r; p[1]<=s; p[1]++) { for(p[2]=t; p[2]<=u; p[2]++) { if((p[1]>v) || (p[2]>v)) { initial(); c=0; do { reverse(); add(); sort(); c=c+1; } while (test()==0); if((test()==2) && (n>length)) { fprintf(outf,"%d_%d %d_%d ",d[1],p[1],d[2],p[2]); printf("%d_%d %d_%d ",d[1],p[1],d[2],p[2]); write(); } } } close(outf); } } void initial() { int i,j,k,c; for(i=1;i<=SIZE;i++) a[i]=0; n=2; k=0; for(i=1; i<=n; i++) { for(j=1; j<=p[i]; j++) b[k+j]=d[i]; k=k+p[i]; } n=k; for(i=1; i<=n; i++) a[i]=b[n+1-i]; m=n; } void sort() { int i,j; int num[BASE+1]; for(i=0;i<=BASE-1;i++) num[i]=0; for(i=1;i<=n;i++) num[a[i]]=num[a[i]]+1; j=1; for(i=BASE-1;i>=0;i--) { while (num[i]>0) { a[j]=i; num[i]=num[i]-1; j=j+1; } } while (a[n]==0) n=n-1; } void reverse() { int i; for(i=1;i<=SIZE; i++) b[i]=0; for(i=1;i<=n;i++) b[i]=a[n+1-i]; } void add() { int c,i,t; c=0; for(i=1;i<=n+1;i++) { t=a[i]+b[i]+c; a[i]=t % BASE; c=t/BASE; } if(a[n+1]!=0) { n=n+1; m=n; } } void write() { int i,c,num; fprintf(outf,"%d ",n); printf("%d ",n); num=a[n]; fprintf(outf,"%d_",num); printf("%d_",num); c=1; for(i=n-1;i>=1;i--) if(a[i]==num) c++; else { fprintf(outf,"%d %d_",c,a[i]); printf("%d %d_",c,a[i]); num=a[i]; c=1; } fprintf(outf,"%d\n",c); printf("%d\n",c); } int test() { int st,x,i; st = 0; if(n > 9) if((a[n]==1) && (a[n-1]==2) && (a[1]==4) && (a[2]==4) && (a[3]==4) && (a[4]==4)) { x=0; for(i=5; i<=n-2; i++) if(a[i]!=3) x=1; if(x==0) st=3; } if((st==0) && (c>iter)) st=2; if((st==0) && (n<=length)) st=1; return st; }