OFFSET
0,1
COMMENTS
In base r the first zero is allowed if there is no zero to the right.
LINKS
Peter J. C. Moses, Table of n, a(n) for n = 0..9999
EXAMPLE
1) Let n=5. For r=2, (5)_2=101, for r=3, (5)_3=012. Thus a(5)=3.
2) Let n=18. For r=2, (18)_2=10010, for r=3, (18)_3=200, (18)_4=102. Since {1,0,2} is a permutation of {0,1,2}, a(18)=4.
MATHEMATICA
Table[NestWhile[#1+1&, 2, (!(#1+1==#2||#1==#2&)[Sort[#1], Range[Length[#1]]]&)[IntegerDigits[n, #1]]&], {n, 0, 200}]
PROG
(PARI) isperm(N)={my(c:small, x:vec, y:vecsmall, z:vecsmall); for(B=2, max(2, N-1), y=Vecsmall(digits(N, B)); x=vector(#y, i, i); for(i=1, #y, if(!y[i], y[i]=x[#x]; break)); z=Vecsmall(0, #y); c=0; for(i=1, #y, c+=vecsearch(x, y[i])&&if(!z[y[i]], z[y[i]]=1; 1, break)); if(c==#y, return(B))); return(0)}
a(n)={my(c=isperm(n)); if(!c, max(2, n), c)} \\ R. J. Cano, May 14 2017
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Vladimir Shevelev, Feb 03 2013
STATUS
approved