login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Decimal representation of permutations of lengths 1, 2, 3, ...
1

%I #15 May 29 2024 13:48:19

%S 1,21,312,132,231,321,4123,1423,2413,4213,1243,2143,3412,4312,1342,

%T 3142,4132,1432,2341,3241,4231,2431,3421,4321,51234,15234,25134,52134,

%U 12534,21534,35124,53124,13524,31524,51324,15324,23514,32514,52314,25314,35214,53214,12354,21354,31254

%N Decimal representation of permutations of lengths 1, 2, 3, ...

%C One way to generate the permutations is by using the factorial base (not to be confused with the Lehmer code).

%C Here is a detailed example showing how to compute a(2982).

%C We have i = 2982 = (4, 0, 4, 1, 0, 0, 0) in the factorial base.

%C So the initial vector "0" is (1, 2, 3, 4, 5, 6, 7), using seven active digits.

%C The factorial base vector is reversed, giving (0, 0, 0, 1, 4, 0, 4).

%C The instructions are to read from the factorial base vector, producing rotations to the right by as many steps as the column says, in the following order:

%C Start on the right; on the vector "0", a rotation of 4 units is made

%C (0, 0, 0, 1, 4, 0, [4])

%C (1, 2, 3, 4, 5, 6, 7)

%C The result is:

%C (4, 5, 6, 7, 1, 2, 3)

%C The 3 is retained, one column is advanced.

%C Next a rotation of 0 units is made (the null rotation)

%C (0, 0, 0, 1, 4, [0], 4)

%C (4, 5, 6, 7, 1, 2, 3)

%C The result is:

%C (4, 5, 6, 7, 1, 2, 3)

%C The 2 is retained, one column is advanced.

%C Now a rotation of 4 units is made

%C (0, 0, 0, 1, [4], 0, 4)

%C (4, 5, 6, 7, 1, 2, 3)

%C The result is:

%C (5, 6, 7, 1, 4, 2, 3)

%C The 4 is retained, one column is advanced.

%C Now a rotation of 1 units is made

%C (0, 0, 0, [1], 4, 0, 4)

%C (5, 6, 7, 1, 4, 2, 3)

%C The result is:

%C (1, 5, 6, 7, 4, 2, 3)

%C The 7 is retained, one column is advanced.

%C Now 3 null rotations are made.

%C All remaining values are retained: 6, 5, and 1

%C Thus 2982 represents the permutation: (1, 5, 6, 7, 4, 2, 3)

%C Or a(2982) = 1567423.

%e The sequence may be regarded as a triangle, where each row consists of permutations of N terms; i.e., we have

%e 1/,2,1/,3,1,2;1,3,2;2,3,1;3,2,1/4,1,2,3;1,4,2,3;2,4,1,3;...

%e Append to each an infinite number of fixed terms and we get a list of rearrangements of the natural numbers, but with only a finite number of terms permuted:

%e 1/2,3,4,5,6,7,8,9,...

%e 2,1/3,4,5,6,7,8,9,...

%e 3,1,2/4,5,6,7,8,9,...

%e 1,3,2/4,5,6,7,8,9,...

%e 2,3,1/4,5,6,7,8,9,...

%e 3,2,1/4,5,6,7,8,9,...

%e 4,1,2,3/5,6,7,8,9,...

%e 1,4,2,3/5,6,7,8,9,...

%e 2,4,1,3/5,6,7,8,9,...

%e Alternatively, if we take only the first n terms of each such infinite row, then the first n! rows give all permutations of the elements 0,1,2,...,n-1.

%o (Visual Basic)

%o ' The following program is developed in Visual Basic, and works for N = 0 to N = 9.

%o ' This restriction is imposed by the number of lines in Excel spreadsheets.

%o ' In this example, N = 5.

%o ' To modify N, you should only change the definition of Dim A(5) to Dim A(N), and

%o change the value in N = 5.

%o Option Explicit

%o Dim Fila As Double, N As Double

%o Dim A(5) As Double

%o Sub Factorial()

%o Dim J As Double, M As Double, O As Double, Y As Double, I As Double

%o Dim Z As Double, R As Double, V As Double, Aux As Double

%o Fila = 0

%o M = 1

%o N = 5

%o For J = 1 To N

%o A(J) = J

%o M = M * A(J)

%o Next J

%o For Fila = 0 To M - 1

%o V = M

%o Z = N

%o Do While Z > 1

%o V = V / Z

%o If Fila Mod V = 0 Then

%o R = Z

%o Z = 1

%o Else

%o Z = Z - 1

%o End If

%o Loop

%o Y = R \ 2

%o If Y > 0 Then

%o For Z = 1 To Y

%o Aux = A(Z)

%o A(Z) = A(R - Z + 1)

%o A(R - Z + 1) = Aux

%o Next Z

%o Call PrintData

%o End If

%o Next Fila

%o End Sub

%o Sub PrintData()

%o Dim I As Integer

%o For I = 1 To N

%o Range("A1:G5040").Cells(Fila + 1, I) = N + 1 - A(I)

%o Next I

%o End Sub

%K nonn

%O 0,2

%A _Raúl Mario Torres Silva_, Feb 14 2019