Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Matlab calculation of the OEIS sequences A239303 and A239304
- % The class bin is found here: http://pastebin.com/K02wGsae
- SeqCV = sym(zeros(1,9870)) ;
- CountCV = 1 ;
- SeqPerms = [] ;
- for m=1:140 % because triangular(140)=9870, and OEIS b-files can have up to 10000 entries
- % create Mat (binary square matrix of order m)
- if mod(m,2) == 0 % if m is even
- MatTRBL = logical(eye(m/2)) ;
- MatTL = fliplr(MatTRBL) ;
- MatBR = [ false(1,m/2) ; [ false(m/2-1,1) fliplr(logical(eye(m/2-1))) ] ] ;
- Mat = [ MatTL MatTRBL ; MatTRBL MatBR ] ;
- else % if m is odd
- MatTL = fliplr(logical(eye(ceil(m/2)))) ;
- MatBR = fliplr(logical(eye(floor(m/2)))) ;
- MatTR = [ fliplr(MatBR) ; false(1,floor(m/2)) ] ;
- MatBL = MatTR' ;
- Mat = [ MatTL MatTR ; MatBL MatBR ] ;
- end
- % compression matrix to compression vector (interpret columns of Mat as binary numbers)
- for n=1:m
- SeqCV(CountCV) = sym(bin( find(Mat(:,n))-1 )) ;
- CountCV = CountCV+1 ;
- end
- % interpret Mat as graph and the graph as permutation
- Start = find(diag(Mat)) ; % first element of the permutation is the position of the only 1 on the diagonal of Mat
- Perm = [ Start Start ] ; % dirty trick 1
- while 1
- Last = Perm(end-1) ;
- This = Perm(end) ;
- Next = setdiff( find(Mat(This,:)) , Last ) ;
- Perm = [ Perm Next ] ;
- if isempty(Next)
- break
- end
- end
- Perm = Perm(2:end) ; % dirty trick 2
- SeqPerms = [ SeqPerms Perm ] ;
- end
- StrCV = '';
- for m=1:9870
- StrCV = [ StrCV num2str(m) ' ' char(SeqCV(m)) '\n' ] ;
- end
- fid = fopen('BfileCV.txt','wt');
- fprintf(fid,StrCV);
- fclose(fid);
- StrPerms = '';
- for m=1:9870
- StrPerms = [ StrPerms num2str(m) ' ' num2str(SeqPerms(m)) '\n' ] ;
- end
- fid = fopen('BfilePerms.txt','wt');
- fprintf(fid,StrPerms);
- fclose(fid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement