OFFSET
1,3
COMMENTS
Contains every finite sequence of distinct numbers, infinitely many times.
LINKS
Reinhard Zumkeller, Rows n=1..7 of triangle, flattened
Daniel Forgues, Tilman Piesk, et al., Orderings, OEIS Wiki.
Antti Karttunen, Ranking and unranking functions, OEIS Wiki.
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.
EXAMPLE
The permutations can be written as
1,
12, 21,
123, 132, 213, 231, 312, 321, etc.
Write them in order and insert commas.
MATHEMATICA
f[n_] := Permutations[Range@ n, {n}]; Array[f, 4] // Flatten (* Robert G. Wilson v, Dec 18 2012 *)
PROG
(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)))))
(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)))
CROSSREFS
A030299 gives the initial portion of these same permutations as decimally encoded numbers.
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.
KEYWORD
nonn,tabf,changed
AUTHOR
EXTENSIONS
Entry revised by N. J. A. Sloane, Feb 02 2006
Keyword tabf added by Reinhard Zumkeller, Mar 29 2012
STATUS
approved