/* Original code for A055881 by: Joerg Arndt (www.jjj.de) Dec 2012 Sequencer adaptation for A196020 by: R. J. Cano, ( aallggoorriitthhmmuuss_at_gmail.com ), Jan 2013 */ first_diff_mode=0; base=10; n=10; \\ Warning: n should not be greater than 10... never, if all computations are assumed in base-10; fc=vector(n) /* mixed radix numbers (rising factorial base) */ ct=0; a=0; p=vector(n,k,k-1) /* permutation */ t=0; j=0; w=#p; G=sum(y=1,w,p[y]*base^(w-y)); updater()= { ct += 1; /* increment factorial number fc[]: */ j = 1; while ( fc[j] == j, fc[j]=0; j+=1; ); /* scan over nines */ if ( j==n, return() ); /* current is last */ fc[j] += 1; /* update permutation p[], reverse prefix of length j+1: */ a = j; /* next term of A055881 */ j += 1; k = 1; while ( k < j, t=p[j]; p[j]=p[k]; p[k]=t; k+=1; j-=1; ); H=sum(y=1,w,p[y]*base^(w-y)); ans=(H-G)\(base-1); if(first_diff_mode,G=H); /* */ Qq=0; while(ans%base==0, ans/=base; Qq++); \\ Useful for the checking of the "((p-1)!-1) Conjecture". \\ Below return either ans or Qq depending of the attribute you want to know for a(n): The coefficient or the power. /* * / ans; / * */I /**/ Qq; \\ Before enabling this, ensure that first_diff_mode is set to zero!. /**/ } if(!first_diff_mode, print("0")); for(u=1,(n!-1),print(updater())); quit;