algorithmuscanorj

A196020 Sequencer.

Jan 2nd, 2013
656
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /* Original code for A055881 by: Joerg Arndt (www.jjj.de) Dec 2012
  2. Sequencer adaptation for A196020 by: R. J. Cano, ( aallggoorriitthhmmuuss_at_gmail.com ), Jan 2013 */
  3.  
  4. first_diff_mode=0;
  5.  
  6. base=7;
  7.  
  8. n=7; \\  Warning: n should not be greater than 10... never, if all computations are assumed in base-10;
  9.  
  10. fc=vector(n) /* mixed radix numbers (rising factorial base) */
  11.  
  12. ct=0; a=0; p=vector(n,k,k-1) /* permutation */
  13.  
  14. t=0; j=0; w=#p; G=sum(y=1,w,p[y]*base^(w-y));
  15.  
  16. updater()=
  17.  
  18. {
  19.  
  20.         ct += 1;
  21.  
  22.         /* increment factorial number fc[]: */
  23.  
  24.         j = 1;
  25.  
  26.         while ( fc[j] == j,  fc[j]=0;  j+=1; );  /* scan over nines */
  27.  
  28.         if ( j==n,  return() );  /* current is last */
  29.  
  30.         fc[j] += 1;
  31.  
  32.         /* update permutation p[], reverse prefix of length j+1: */
  33.  
  34.         a = j;  /* next term of A055881 */
  35.  
  36.         j += 1;  k = 1;
  37.  
  38.         while ( k < j,
  39.  
  40.             t=p[j]; p[j]=p[k]; p[k]=t;
  41.  
  42.             k+=1; j-=1;
  43.  
  44.         );
  45.  
  46.     H=sum(y=1,w,p[y]*base^(w-y));
  47.  
  48.         ans=(H-G)\(base-1);
  49.  
  50.         if(first_diff_mode,G=H);
  51.  
  52.     /* * /
  53.  
  54.     while(ans%base==0, ans/=base); \\ Useful for the checking of the "((p-1)!-1) Conjecture".
  55.  
  56.     / * */
  57.  
  58.         ans;
  59.  
  60. }
  61.  
  62. if(!first_diff_mode, print("0")); for(u=1,(n!-1),print(updater()));
  63.  
  64. quit;
RAW Paste Data