1. Here it is the code of the first program: This program finds the number signed permutations of length n (n=1,2,...,k) that avoid a signed pattern tau (of length 3,4 or 5) and a positive integer k.
#include <stdio.h>
#define MAXN 13 /*max length of signed permutation*/
#define KK 2 /*two signs positive and negative*/

int n; /*length of the signed permutation*/
int prem[MAXN],bool_prem[MAXN],sii[MAXN]; /*permutation with signs*/
long gg; /*number signed permutations that avoid the pattern */
int mem[10][5],smem[10][5],nn; /*pattern of length nn*/

int order(int a,int b) /*order between two elements*/
{ if (a>b) return 1; else return 0;}

int occ5(int a1,int a2,int a3,int a4,int a5,int b1,int b2,int b3,int b4,int b5) /*order isomorphic two sequence of length five*/
{ int m[11],n[11],i;
m[0]=order(a1,a2); m[1]=order(a1,a3); m[2]=order(a1,a4); m[3]=order(a1,a5);
m[4]=order(a2,a3); m[5]=order(a2,a4); m[6]=order(a2,a5);
m[7]=order(a3,a4); m[8]=order(a3,a5);
m[9]=order(a4,a5); m[10]=1;
n[0]=order(b1,b2); n[1]=order(b1,b3); n[2]=order(b1,b4); n[3]=order(b1,b5);
n[4]=order(b2,b3); n[5]=order(b2,b4); n[6]=order(b2,b5);
n[7]=order(b3,b4); n[8]=order(b3,b5);
n[9]=order(b4,b5); n[10]=0;
for(i=0;i<10;i++) if (m[i]!=n[i]) return 0;
return 1;
}

int occ4(int a1,int a2,int a3,int a4,int b1,int b2,int b3,int b4) /*order isomorphic two sequence of length four*/
{ int m[10],n[10],i;
m[0]=order(a1,a2); m[1]=order(a1,a3); m[2]=order(a1,a4);
m[3]=order(a2,a3); m[4]=order(a2,a4);
m[5]=order(a3,a4);
n[0]=order(b1,b2); n[1]=order(b1,b3); n[2]=order(b1,b4);
n[3]=order(b2,b3); n[4]=order(b2,b4);
n[5]=order(b3,b4);
for(i=0;i<6;i++) if (m[i]!=n[i]) return 0;
return 1;
}

int occ3(int a1,int a2,int a3,int b1,int b2,int b3) /*order isomorphic two sequence of length three*/
{ int m[3],n[3],i;
m[0]=order(a1,a2); m[1]=order(a1,a3); m[2]=order(a2,a3);
n[0]=order(b1,b2); n[1]=order(b1,b3); n[2]=order(b2,b3);
for(i=0;i<3;i++) if (m[i]!=n[i]) return 0;
return 1;
}

int avoids55() /*avoids five letter pattern*/
{ int i2,i3,i4,i5,i6;
for(i2=0;i2 for(i3=i2+1;i3 for(i4=i3+1;i4 for(i5=i4+1;i5 for(i6=i5+1;i6 {if (occ5(prem[i2],prem[i3],prem[i4],prem[i5],prem[i6],mem[nn][0],mem[nn][1],mem[nn][2],mem[nn][3],mem[nn][4])==1)
if((sii[i2]==smem[nn][0])&&(sii[i3]==smem[nn][1])&&(sii[i4]==smem[nn][2])&&(sii[i5]==smem[nn][3])&&(sii[i6]==smem[nn][4])) return(0);
}
return(1);
}

int avoids44() /*avoids four letter pattern*/
{int i3,i4,i5,i6;
for(i3=0;i3 for(i4=i3+1;i4 for(i5=i4+1;i5 for(i6=i5+1;i6 {if (occ4(prem[i3],prem[i4],prem[i5],prem[i6],mem[nn][0],mem[nn][1],mem[nn][2],mem[nn][3])==1)
if ((sii[i3]==smem[nn][0])&&(sii[i4]==smem[nn][1])&&(sii[i5]==smem[nn][2])&&(sii[i6]==smem[nn][3]) ) return(0);
}
return(1);
}

int avoids33() /*avoids three letter pattern*/
{ int i4,i5,i6;
for(i4=0;i4 for(i5=i4+1;i5 for(i6=i5+1;i6 { if (occ3(prem[i4],prem[i5],prem[i6],mem[nn][0],mem[nn][1],mem[nn][2])==1)
if ( (sii[i4]==smem[nn][0])&&(sii[i5]==smem[nn][1])&&(sii[i6]==smem[nn][2]) ) return(0);
}
return(1);
}

void patterns()
{ int i,j,ma;
long dd=1;
for(j=0;j for(ma=0;ma { if (nn==5) if (avoids55()==1) gg++; /*count how many avoid*/
if (nn==4) if (avoids44()==1) gg++;
if (nn==3) if (avoids33()==1) gg++;
i=n-1; while((sii[i]==KK)&&(i>0)) i=i-1;
sii[i]=sii[i]+1; for (j=i+1;j }}

void builtpremutation(int l) /*scanning permutations*/
{ int j;
if (l==n-1)
{j=0; while (bool_prem[j]==1) j++; prem[l]=j; patterns();}
else
{for(j=0;j if (bool_prem[j]==0) { bool_prem[j]=1; prem[l]=j; builtpremutation(l+1); bool_prem[j]=0;}
}
}

void main()
{ int i,j,kk;
nn=0;
printf(" W R I T T E N B Y T O U F I K M A N S O U R\n\n");
printf("This program finds the sequence B_n(tau) for given a pattern\n");
printf(" tau of length either 3,4 or 5, and given a positive integer\n");
printf(" number k such that n=1,2,...,k\n\n");
printf("In order to do that, please give me the foloowing data\n");
printf(" Length of the pattern tau (3,4,5):"); scanf("%d",&nn);
printf(" The pattern tau (for example as 1 -3 2): tau="); for(i=0;i printf(" The value of k (k<13): k="); scanf("%d",&k);

for(i=0;i if (mem[nn][i]<0)
{ mem[nn][i]=-mem[nn][i]; smem[nn][i]=2;}
else
{ smem[nn][i]=1;}
for(n=1;n<=kk;n++) /*length of signed permutations that will scan*/
{
for(i=0;i gg=0;
builtpremutation(0); /*scan the signed pemrutations*/

printf("#B_%d(",n); /*print the number signed permutations that avoid the pattern*/
for(j=0;j if(smem[nn][j]==1) printf("%d ",mem[nn][j]);
else printf("-%d ",mem[nn][j]);
printf(") = %d\n",gg);
}
}

2) Here it is the code of the second program: The second program classifies the classes of patterns of length 5 up to symmetry and Theorem 2.1 (as described in the corresponding paper).

#include <stdio.h>
FILE *inp,*out;
int mem[3900][5],smem[3900][5],cll[3900],nn; /*the list of the signed patterns of length 5 */
int a[5],sa[5]; /*the current pattern*/

void barp() /*baring operation*/
{int i; for(i=0;i<5;i++) if (sa[i]==1) sa[i]=2; else sa[i]=1;}

void revp() /*reversal operation*/
{int i,b[5],sb[5]; for(i=0;i<5;i++) {sb[i]=sa[4-i]; b[i]=a[4-i];} for(i=0;i<5;i++) {sa[i]=sb[i]; a[i]=b[i];}}

void compp() /*complement operation*/
{int i,b[5]; for(i=0;i<5;i++) b[i]=6-a[i]; for(i=0;i<5;i++) a[i]=b[i];}

void invp() /*inverse operation*/
{int i,b[5],sb[5]; for(i=0;i<5;i++) {sb[a[i]-1]=sa[i]; b[a[i]-1]=i+1;} for(i=0;i<5;i++) {sa[i]=sb[i]; a[i]=b[i];}}

void symmetric(int m1, int m2) /*classes up to syymetry operation*/
{ int j,fg,b[5],sb[5];
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
revp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
barp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); revp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); barp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
revp(); barp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
revp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
barp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); revp(); barp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); revp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
compp(); barp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
revp(); barp(); invp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
for(j=0;j<5;j++) {b[j]=mem[m1][j]; sb[j]=smem[m1][j]; a[j]=mem[m2][j]; sa[j]=smem[m2][j];}
barp(); invp(); revp(); compp(); fg=0; for(j=0;j<5;j++) if((b[j]==a[j])&&(sb[j]==sa[j])) fg++; if (fg==5) cll[m2]=0;
}

void main()
{ int i,j,jj,s,nm; char cc;
printf(" W R I T T E N B Y M A N S O U R T O U F I K\n\n");
printf("This program fins the symmetric classes of 5 letter signed patterns\n");
printf(" up to four symmetric operations, reversal, complement, inverse, and baring.\n");
printf(" In order to do that the program needs input file, called 'sign5', which\n");
printf(" contains all the 5 letter signed patterns as one long row of length 10x3940,\n");
printf(" where there are 2^5*120=3940 patterns of length 5, and 10 the code of each\n");
printf(" with code as abcdefghij and abcde is permutation of length 5 and fghij is a\n");
printf(" word on the letters 1 and 2 only.\n\n");
printf("The output will be in the file 'symmt' in the same folder which contains all\n");
printf(" the symmetric classes (284) and then all the symmetric classes after applying\n");
printf(" Theorem 2.1 as described in the paper.\n\n");
inp=fopen("sign5","r"); /*file contains all the patterns of length 5*/
for(i=0;i<3840;i++)
{
fscanf(inp,"%c",&cc); mem[i][0]=cc-48; fscanf(inp,"%c",&cc); mem[i][1]=cc-48;
fscanf(inp,"%c",&cc); mem[i][2]=cc-48; fscanf(inp,"%c",&cc); mem[i][3]=cc-48;
fscanf(inp,"%c",&cc); mem[i][4]=cc-48; fscanf(inp,"%c",&cc); smem[i][0]=cc-48;
fscanf(inp,"%c",&cc); smem[i][1]=cc-48; fscanf(inp,"%c",&cc); smem[i][2]=cc-48;
fscanf(inp,"%c",&cc); smem[i][3]=cc-48; fscanf(inp,"%c",&cc); smem[i][4]=cc-48;
cll[i]=1;
}
fclose(inp);

for(i=0;i<3840;i++)
for(j=i+1;j<3840;j++)
if (cll[j]==1) symmetric(i,j);
printf("\n------------------------------------------------------------\n");
jj=0; /*printing symmetric classes*/
out=fopen("symmt","w");
for(i=0;i<3840;i++)
if(cll[i]==1)
{
jj++;
printf("%3d) ",jj);,br> for(j=0;j<5;j++) if (smem[i][j]==2) printf("-%d ",mem[i][j]); else printf("%2d ",mem[i][j]);
fprintf(out,"%3d) ",jj);
for(j=0;j<5;j++) if (smem[i][j]==2) fprintf(out,"-%d ",mem[i][j]); else fprintf(out,"%2d ",mem[i][j]);,br> printf("\n");
fprintf(out,"\n");
}
for(i=0;i<3840;i++) /*Applying the symmetry in Theorem 2.1*/
if (cll[i]==1)
{
if(mem[i][0]==1) if(smem[i][1]!=1) cll[i]=0;
if((mem[i][0]==1)&&(mem[i][1]==2)) if(smem[i][2]!=1) cll[i]=0;
if((mem[i][0]==2)&&(mem[i][1]==1)&&(smem[i][0]==1)&&(smem[i][1]==1)) cll[i]=0;
if((mem[i][0]==1)&&(mem[i][1]==2)&&(mem[i][2]==3))
if(smem[i][3]!=1) cll[i]=0;
if((mem[i][0]==3)&&(mem[i][1]==2)&&(mem[i][2]==1)&&(smem[i][0]==1)&&(smem[i][1]==1)&&(smem[i][2]==1)) cll[i]=0;
if((mem[i][0]==1)&&(mem[i][1]==2)&&(mem[i][2]==3)&&(mem[i][3]==4)) if(smem[i][4]!=1) cll[i]=0;
if((mem[i][0]==4)&&(mem[i][1]==3)&&(mem[i][2]==2)&&(mem[i][3]==1)&&(smem[i][0]==1)&&(smem[i][1]==1)&&(smem[i][2]==1)&&(smem[i][3]==1)) cll[i]=0;
}
for(i=0;i<3840;i++)
if (cll[i]==1)
{
if((mem[i][0]==2)&&(mem[i][1]==1))
if((smem[i][0]==1)&&(smem[i][1]==1)) cll[i]=0;
if((mem[i][0]==3)&&(mem[i][1]==2)&&(mem[i][2]==1))
if((smem[i][0]==1)&&(smem[i][1]==1)&&(smem[i][2]==1)) cll[i]=0;
if((mem[i][0]==4)&&(mem[i][1]==3)&&(mem[i][2]==2)&&(mem[i][3]==1))
if((smem[i][0]==1)&&(smem[i][1]==1)&&(smem[i][2]==1)&&(smem[i][3]==1)) cll[i]=0;
if((mem[i][0]==5)&&(mem[i][1]==4)&&(mem[i][2]==3)&&(mem[i][3]==2)&&(mem[i][4]==1))
if((smem[i][0]==1)&&(smem[i][1]==1)&&(smem[i][2]==1)&&(smem[i][3]==1)&&(smem[i][4]==1)) cll[i]=0;
}
jj=0;
for(i=0;i<3840;i++) /*printing the classes after applying Theorem 2.1*/
if(cll[i]==1)
{
jj++; printf("%3d) ",jj);
for(j=0;j<5;j++) if (smem[i][j]==2) printf("-%d ",mem[i][j]); else printf("%2d ",mem[i][j]);
fprintf(out,"%3d) ",jj);
for(j=0;j<5;j++) if (smem[i][j]==2) fprintf(out,"-%d ",mem[i][j]); else fprintf(out,"%2d ",mem[i][j]);
printf("\n"); fprintf(out,"\n");
}
fclose(out);
}