// create dir Scilab if it does not exist
[str,ok] = dos('whoami');
TOKENS = [];
token = strtok(str,"\");
TOKENS = [TOKENS,token];
while( token <> '' )
  token = strtok("\");
  TOKENS = [TOKENS,token];
end
Utilisateur=TOKENS(2);
cd ('C:\Users\' + Utilisateur +'\Documents' );
sc=createdir("Scilab") ;
cd Scilab ;
sc=createdir("TestPermute") ;
cd TestPermute ;
sc=createdir("Work");
WorkPath = pwd() ;
WorkPath = WorkPath  + "\Work" ;
exec("Permute.sci"); // load the functions
CsvDelimiter=',' ;
d=getdate();



txt = ['Enter the Permutation List on this form';'n of Sn'];
sig = x_mdialog('the list can have many products',txt,['[ 3 4 ]*[ 2 5]';'5']);

TOKENS = [];
token = strtok(sig(1),"*");
TOKENS = [TOKENS,token];
while( token <> '' )
  token = strtok("*");
  TOKENS = [TOKENS,token];
end
disp(TOKENS);
disp(size(TOKENS)) ;
ListLikeThat=list();
SstrH=sig(1) ;
for i=1:size(TOKENS)(2)-1
 disp(TOKENS(i)+string(i)); 
 ListLikeThat= lstcat( ListLikeThat,evstr(TOKENS(i)) ) ;  
end
disp(ListLikeThat);


d=getdate();
TestFile = mopen(WorkPath +'\MatrixPermutations-'+string(d(7))+'H'+string(d(8))+'m Size'+sig(2)+'.txt', 'at');


mfprintf(TestFile," %s\n",SstrH);
mfprintf(TestFile," %s\n",'');
Sn=26 ;// Alphabet letters Number
Sn=6 ;// only !
Sn=evstr(sig(2)) ;// what has been put in only !
// convert 1:Sn in letters
ThisS=ascii((1:Sn)+64);
[SL,SSL]  = ListPermuteThis(ThisS,ListLikeThat,1);
M=eye(length(ThisS),length(ThisS));
LikeThisColumn=SL;
[m]  = PermuteMatrixColumn(M,LikeThisColumn) ;
for r = 1 : size(m)(1)
    Str='';
    for c = 1 : size(m)(2)
      Str=Str + string(m(r,c)) + ' ';
    end
    mfprintf(TestFile," %s\n",Str);
end
ListA=list();
vt=length(ThisS):-1:1 ;
mThisS=[];
for i = 1 : length(ThisS)
  mThisS=[mThisS part(ThisS, i) ] ;
end
AllPermutations=perms(mThisS);

AllPermutationsStr=[];
for r = 1 : size(AllPermutations)(1)
    Str='';
    for c = 1 : size(AllPermutations)(2)
        Str=Str + string(AllPermutations(r,c));
    end
    AllPermutationsStr=[AllPermutationsStr ; Str] ;
    [ListSeqString,ListSeq ] = GetTheSequence(AllPermutationsStr(r),ThisS) ;
    i=1 ;
    A=[AllPermutationsStr(r)] ;
    SSL=A;
        mfprintf(TestFile,"%3d %s  %s ", r,Str,ListSeqString);
        ListA=list();
    while (SSL ~= ThisS & i < factorial(length(ThisS))) // second term is only for security
        //disp(A);
        [SL,SSL]  = ListPermuteThis(A,ListSeq,1) ;
        A=SSL ;
        i=i+1;
        mfprintf(TestFile," %s ", A);
        
        if dejaVue(ListA,A)==%T then
            disp('deja vue');
            break ;
        else
            ListA($+1)= A;
        end 
    end
    disp( string(r)+':'+string(size(AllPermutations)(1)) );
        mfprintf(TestFile," \n");
end
mclose(TestFile);

