two "find the next term" puzzles from Knuth Vol 4

franktaw at netscape.net franktaw at netscape.net
Mon Nov 20 23:59:41 CET 2006


A123896:

0 1 1 1 12 12 12 12 12 12 100 121 122 123 123 112 123 123 123 123 100 
112 121 123 123 123 121 123 123 123 100 123 1023 1023 1123 1223 1234 
1234 1222 1231 1200 1231 1234 1234 1234 1012 1223 1102 1203 1203 1200 
1203 1203 1203 1234 1023 1213 1234 1123 1234 1200 1234 1233 1232 1023 
1223 1234 1123 1231 1234 1200 1023 1234 1234 1234 1231 1223 1232 1023 
1234 1200 1213 1234 1223 1023 1223 1234 1234 1122 1234 1200

A123902:

0 1 12 100 112 121 122 123 1012 1023 1102 1122 1123 1200 1201 1203 1213 
1222 1223 1231 1232 1233 1234 10000 10012 10023 10102 10123 10201 10202 
10203 10213 10223 10231 10232 10234 11023 11102 11200 11203 11211 11213 
11221 11223 11232 11234 12003 12013 12023 12032 12033 12034 12100 12113 
12121 12131 12133 12134 12200 12203 12212 12213 12231 12232 12233 12234 
12300 12301 12304 12312 12313 12314 12321 12323 12324 12331 12332 12334 
12341 12342

Sorry, I didn't use Mathematica, Maple, or even PARI; I used Excel and 
VBA.

Here's a VBA program:

Public Function RestrictedGrowthString(ByVal x As String) As String
    Dim i As Long
    Dim dig As Integer
    Dim pos As Long

    For i = 1 To Len(x)
        If Mid(x, i, 1) = "0" Then
            RestrictedGrowthString = RestrictedGrowthString & "0"
        Else
            pos = InStr(x, Mid(x, i, 1))
            If pos = i Then
                dig = dig + 1
                 RestrictedGrowthString = RestrictedGrowthString & 
Format(dig)
            Else
                 RestrictedGrowthString = RestrictedGrowthString & 
Mid(RestrictedGrowthString, pos, 1)
            End If
        End If
    Next i
End Function

Franklin T. Adams-Watters


-----Original Message-----
From: njas at research.att.com

the two puzzles (and their solutions) are

%I A123896
%S A123896 0,1,1,1,12,12,12,12,12,12,100,121,122,123,123
%N A123896 A123895(n^2).
...

%I A123902
%S A123902 0,1,12,100,112,121,122,123
%N A123902 A123896 sorted and uniqued.
...

which are based on this:

%I A123895
%S A123895 
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,
%T A123895 
12,12,12,12,12,10,12,12,11,12,12,12,12,12,12,10,12,12,12,11,12,12,
%U A123895 
12,12,12,10,12,12,12,12,11,12,12,12,12,10,12,12,12,12,12,11,12,12
%N A123895 Restricted growth string for the (decimal expansion of the) 
number n.
%C A123895 Write n in base 10 prefixed with a 0. Read this string from 
left to r
ight. 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 t
hird distinct digit, and so on. Finally, delete the leading zeros.
%D A123895 D. E. Knuth, TAOCP, Vol. 4, Section 7.2.1.5, Problems 4 and 
5.
%e A123895 To find a(66041171): 066041171 -> 011023343 -> 11023343.
%Y A123895 Cf. A123896, A123902.
%K A123895 nonn,base,new
%O A123895 0,11
%A A123895 njas, Nov 20 2006

It would be nice if someone could extend the first two, and provide
maple or mma or other code for the third one

Neil


________________________________________________________________________
Check Out the new free AIM(R) Mail -- 2 GB of storage and 
industry-leading spam and email virus protection.







More information about the SeqFan mailing list