cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-4 of 4 results.

A030298 List of permutations of 1,2,3,...,n for n=1,2,3,..., in lexicographic order.

Original entry on oeis.org

1, 1, 2, 2, 1, 1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1, 1, 2, 3, 4, 1, 2, 4, 3, 1, 3, 2, 4, 1, 3, 4, 2, 1, 4, 2, 3, 1, 4, 3, 2, 2, 1, 3, 4, 2, 1, 4, 3, 2, 3, 1, 4, 2, 3, 4, 1, 2, 4, 1, 3, 2, 4, 3, 1, 3, 1, 2, 4, 3, 1, 4, 2, 3, 2, 1, 4, 3, 2, 4, 1, 3, 4, 1, 2, 3, 4, 2, 1, 4, 1, 2, 3, 4, 1, 3, 2, 4, 2
Offset: 1

Views

Author

Keywords

Comments

Contains every finite sequence of distinct numbers, infinitely many times.

Examples

			The permutations can be written as
  1,
  12, 21,
  123, 132, 213, 231, 312, 321, etc.
Write them in order and insert commas.
		

Crossrefs

A030299 gives the initial portion of these same permutations as decimally encoded numbers.
Cf. A001563 (row lengths), A001286 (row sums).
Cf. A030496 for another ordering.
The same information is essentially given in A055089, but in more compact way, by skipping those permutations which start with a fixed element (cf. A220696).
A220660(n) tells the zero-based rank r of the n-th permutation in this sequence, among all finite permutations of the same size.
A220663(n) tells the zero-based position (from the left) of that a(n) in that permutation of rank r.
A084557(n) tells that the n-th term a(n) belongs to the a(n):th lexicographically ordered permutation from the start (its "global rank").
A220660(A084557(n)) tells the "local rank" of the permutation (amongst the permutations of the same size) to which the n-th term a(n) belongs.
(A130664(n),A084555(n)) = (1,1),(2,3),(4,5),(6,8),(9,11),(12,14),... gives the starting and ending offsets of the n-th permutation in this list.

Programs

  • Haskell
    import Data.List (permutations, sort)
    a030298 n k = a030298_tabf !! (n-1) (k-1)
    a030298_row = concat . sort . permutations . enumFromTo 1
    a030298_tabf = map a030298_row [1..]
    -- Reinhard Zumkeller, Mar 29 2012
    (MIT/GNU Scheme, with Antti Karttunen's intseq-library):
    ;; Note that in Scheme, vector indexing is zero-based.
    ;; Requires also A055089permvec from A055089.
    (define (A030298 n) (vector-ref (A030298permvec (A084556 (A084557 n)) (A220660 (A084557 n))) (A220663 n)))
    (define (A030298permvec size rank) (vector-reverse (vector1invert (A055089permvec size rank))))
    (define (vector1invert vec) (make-initialized-vector (vector-length vec) (lambda (i) (1+ (- (vector-length vec) (vector-ref vec i))))))
    (define (vector-reverse vec) (make-initialized-vector (vector-length vec) (lambda (i) (vector-ref vec (- (vector-length vec) i 1)))))
    
  • Mathematica
    f[n_] := Permutations[Range@ n, {n}]; Array[f, 4] // Flatten (* Robert G. Wilson v, Dec 18 2012 *)
  • Python
    from itertools import permutations, count, chain, islice
    def A030298_gen(): # generator of terms
        return chain.from_iterable(p for l in count(2) for p in permutations(range(1,l)))
    A030298_list = list(islice(A030298_gen(),30)) # Chai Wah Wu, Mar 21 2022

Formula

Start with 1, then 12 and 21, then the 6 permutations of 123 in lexical order: 123, 132, 213, 231, 312, 321 and so on.

Extensions

Entry revised by N. J. A. Sloane, Feb 02 2006
Keyword tabf added by Reinhard Zumkeller, Mar 29 2012

A030299 Decimal representation of permutations of lengths 1, 2, 3, ... arranged lexicographically.

Original entry on oeis.org

1, 12, 21, 123, 132, 213, 231, 312, 321, 1234, 1243, 1324, 1342, 1423, 1432, 2134, 2143, 2314, 2341, 2413, 2431, 3124, 3142, 3214, 3241, 3412, 3421, 4123, 4132, 4213, 4231, 4312, 4321, 12345, 12354, 12435, 12453, 12534, 12543, 13245, 13254, 13425
Offset: 1

Views

Author

Keywords

Comments

This is a list of the permutations in "one-line" notation (cf. Dixon and Mortimer, p. 2). The i-th element of the string is the image of i under the permutation. For example 231 is the permutation that sends 1 to 2, 2 to 3, and 3 to 1. - N. J. A. Sloane, Apr 12 2014
Precise definition of the term "Decimal representation" (required for indices n>409113): Numbers N(s) = Sum_{i=1..m} s(i)*10^(m-i), where s runs over the permutations of (1,...,m), and m=1,2,3,.... This also defines the "lexicographical" order: Obviously 21 comes before 123, etc. The lexicographical order of the permutations, for given m, is the same as the natural order of the numbers N(s). - M. F. Hasler, Jan 28 2013
An alternate variant, using concatenation of the permutations, is very clumsy once the length exceeds 9. For example, after 987654321 (= A030299(409113), where 409113 = A007489(9)) we would get 12345678910, 12345678109, ... In A030298 this problem has been avoided by listing the elements of permutations as separate terms. [Edited by M. F. Hasler, Jan 28 2013]
Sequence A051845 is a base-independent version of this sequence: Permutations of 1...m are considered as numbers written in base m+1. - M. F. Hasler, Jan 28 2013

References

  • John D. Dixon and Brian Mortimer, Permutation groups. Graduate Texts in Mathematics, 163. Springer-Verlag, New York, 1996. xii+346 pp. ISBN: 0-387-94599-7 MR1409812 (98m:20003).

Crossrefs

A007489(n) gives the position (index) of the term corresponding to last permutation of n elements: (n,n-1,...,1).
The first differences A220664 has interesting fractal structure, see A219664 and A217626.
Cf. also A030298, A055089, A060117, A181073, A352991 (by concatenation).
See A240763 for preferential arrangements.

Programs

  • Maple
    seq(seq(add(s[i]*10^(m-i),i=1..m),s=combinat:-permute([$1..m])),m=1..5); # Robert Israel, Oct 14 2015
  • Mathematica
    Flatten @ Table[FromDigits /@ Permutations[Table[i,{i,n}]],{n,9}] (* For first 409113 terms; Zak Seidov, Oct 03 2015 *)
  • PARI
    is_A030299(n)={ (n>1234567890 & print("maybe")) || vecsort(digits(n))==vector(#Str(n),i,i) } \\ /* use digits(n)=eval(Vec(Str(n))) in older versions lacking this function */ \\ M. F. Hasler, Dec 12 2012
    (MIT/GNU Scheme)
    ;; Antti Karttunen, Dec 18 2012
    ;; Requires also code from A030298 and A055089:
    (define (A030299 n) (vector->base-k (A030298permvec (A084556 n) (A220660 n)) 10))
    (define (vector->base-k vec k) (let loop ((i 0) (s 0)) (cond ((= (vector-length vec) i) s) ((>= (vector-ref vec i) k) (error (format #f "Cannot interpret vector ~a in base ~a!" vec k))) (else (loop (+ i 1) (+ (* k s) (vector-ref vec i)))))))
    
  • Python
    from itertools import permutations
    def pmap(s, m): return sum(s[i-1]*10**(m-i) for i in range(1, len(s)+1))
    def agen():
      m = 1
      while True:
        for s in permutations(range(1, m+1)): yield pmap(s, m)
        m += 1
    def aupton(terms):
      alst, g = [], agen()
      while len(alst) < terms: alst += [next(g)]
      return alst
    print(aupton(42)) # Michael S. Branicky, Jan 12 2021

Extensions

Edited by N. J. A. Sloane, Feb 23 2010

A220661 Irregular table, where the n-th row consists of numbers 1..n!

Original entry on oeis.org

1, 1, 2, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39
Offset: 1

Views

Author

Antti Karttunen, Dec 18 2012

Keywords

Examples

			Rows of this irregular table begin as:
1;
1, 2;
1, 2, 3, 4, 5, 6;
		

Crossrefs

Programs

Formula

a(n) = n - A007489(A084556(n)-1).
a(n) = A220660(n)+1.

A220662 Irregular table: row n (n>=1) consists of A084556(n) copies of A130664(n).

Original entry on oeis.org

1, 2, 2, 4, 4, 6, 6, 6, 9, 9, 9, 12, 12, 12, 15, 15, 15, 18, 18, 18, 21, 21, 21, 24, 24, 24, 24, 28, 28, 28, 28, 32, 32, 32, 32, 36, 36, 36, 36, 40, 40, 40, 40, 44, 44, 44, 44, 48, 48, 48, 48, 52, 52, 52, 52, 56, 56, 56, 56, 60, 60, 60, 60, 64, 64, 64, 64, 68
Offset: 1

Views

Author

Antti Karttunen, Dec 18 2012

Keywords

Comments

The term a(n) gives the position of the first term in A030298 which belongs to the same permutation as A030298(n) itself.

Examples

			Rows of this irregular table begin as:
1;
2, 2;
4, 4;
6, 6, 6;
9, 9, 9;
		

Crossrefs

Formula

a(n) = A130664(A084557(n)) = A084555(A084557(n)-1)+1.
a(A130664(n)) = A130664(n).
Showing 1-4 of 4 results.