Advertisement
mate2code

Bit permutations (oeis.org/A195665)

Aug 1st, 2013
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.02 KB | None | 0 0
  1. % code to calculate bit-permutations, here matrix M of size 120x32
  2. % below calculations for OEIS A195665
  3.  
  4. num = 5 ;
  5. fnum = factorial(num) ;
  6. pnum = 2^num ;
  7.  
  8. Powtwo = zeros(1,num) ;
  9. for m=1:num
  10.     Powtwo(m) = 2^(m-1) ;
  11. end
  12.  
  13. Perms = perms(Powtwo) ;  % all permutations
  14. Perms = horz(sortrows(horz(Perms))) ;  % reverse colex
  15.  
  16. % matrix
  17.  
  18. M = zeros( fnum , pnum ) ;
  19. for m=1:fnum
  20.     M(m,1:pnum) = cv2wp( Perms(m,:) ) ;  % compression vector to Walsh permutation
  21. end
  22.  
  23. % sequence
  24.  
  25. Fact = 1 ;  % when m reaches this factorial, the current row length will be applied the last time, than doubled
  26. Count = 2 ;  % used to calculate the next Fact
  27. Length = 2 ;  % current row length
  28. S = [] ;
  29. for m=1:fnum
  30.     S = [ S M(m,1:Length) ] ;
  31.     if m == Fact
  32.         Fact = Fact * Count ;
  33.         Count = Count + 1 ;
  34.         Length = 2 * Length ;
  35.     end
  36. end
  37.    
  38. % b-file
  39.  
  40. B = '' ;
  41. for m=1:length(S)
  42.     B = [ B num2str(m-1) ' ' num2str(S(m)) '\n' ] ;
  43. end
  44. fid = fopen('bfile','wt');
  45. fprintf(fid,char(B));
  46. fclose(fid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement