Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #27 Jul 24 2021 01:13:33
%S 0,1,1,1,1,1,1,1,1,1,10,11,12,12,12,12,12,12,12,12,10,12,11,12,12,12,
%T 12,12,12,12,10,12,12,11,12,12,12,12,12,12,10,12,12,12,11,12,12,12,12,
%U 12,10,12,12,12,12,11,12,12,12,12,10,12,12,12,12,12,11,12,12
%N Restricted growth string for the (decimal expansion of the) number n.
%C Write n in base 10 prefixed with a 0. Read this string from left to right. Write a 0 each time you see the first distinct digit (which is 0), write a 1 each time you see the second distinct digit, write a 2 each time you see the third distinct digit and so on. Finally, delete the leading 0's.
%D D. E. Knuth, The Art of Computer Programming, vol. 4A, Combinatorial Algorithms, Section 7.2.1.5, p. 432, Problems 4 and 5.
%H Michael De Vlieger, <a href="/A123895/b123895.txt">Table of n, a(n) for n = 0..10000</a>
%e To find a(66041171): 066041171 -> 011023343 -> 11023343.
%p read("transforms"):
%p A123895 := proc(n)
%p local dgs,Lmap,idx,dig,pos,Lredu ;
%p dgs := [op(convert(n,base,10)) ,0];
%p Lmap := [] ;
%p for idx from -1 to -nops(dgs) by -1 do
%p dig := op(idx,dgs) ;
%p if not member(dig,Lmap) then
%p Lmap := [op(Lmap),dig] ;
%p end if;
%p end do:
%p Lredu := [] ;
%p for idx from -1 to -nops(dgs) by -1 do
%p member(op(idx,dgs),Lmap,'pos') ;
%p Lredu := [op(Lredu),pos-1] ;
%p end do:
%p digcatL(Lredu) ;
%p end proc:
%p seq(A123895(n),n=0..60) ; # _R. J. Mathar_, Dec 09 2015
%t f[n_] := Block[{d = Prepend[IntegerDigits@ n, 0], a, b, w}, b = DeleteDuplicates@ d; a = Range[0, Length@ b]; w = FromDigits@ Flatten[Part[a, FirstPosition[b, #]] & /@ d]; w]; Table[f@ n, {n, 0, 67}] (* _Michael De Vlieger_, Dec 09 2015, Version 10 *)
%o (VBA)
%o Public Function RestrictedGrowthString(ByVal x As String) As String
%o Dim i As Long
%o Dim dig As Integer
%o Dim pos As Long
%o For i = 1 To Len(x)
%o If Mid(x, i, 1) = "0" Then
%o RestrictedGrowthString = RestrictedGrowthString & "0"
%o Else
%o pos = InStr(x, Mid(x, i, 1))
%o If pos = i Then
%o dig = dig + 1
%o RestrictedGrowthString = RestrictedGrowthString &
%o Format(dig)
%o Else
%o RestrictedGrowthString = RestrictedGrowthString &
%o Mid(RestrictedGrowthString, pos, 1)
%o End If
%o End If
%o Next i
%o End Function
%o ' _Franklin T. Adams-Watters_
%Y Cf. A123896, A123902.
%K nonn,base
%O 0,11
%A _N. J. A. Sloane_, Nov 20 2006