OFFSET
2,1
COMMENTS
a(n) is also equal to the sum over all permutations p in S(n) of the number of elements in the set {(i, j): 0 < i < j < n+1 and |i - j| = |p(i) - p(j)|}.
REFERENCES
M. Bona, Combinatorics of Permutations, Chapman & Hall/CRC, Boca Raton, FL, 2004, pp. 24-30.
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, 1973, Vol. 3, pp. 46 and 587-8.
FORMULA
EXAMPLE
a(3) = 10 because the permutations 123, 132, 312, 213, 231, 321 have the following alternating runs: 123, 13, 32, 31, 12, 21, 13, 23, 31 and 321.
MAPLE
seq(n!*(2*n-1)/3, n=2..20);
MATHEMATICA
a[n_]:=n!*(2*n-1)/3; Array[a, 20, 2] (* Stefano Spezia, Sep 11 2025 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Emeric Deutsch and Ira M. Gessel, Sep 07 2004
EXTENSIONS
a(22) from Stefano Spezia, Sep 11 2025
STATUS
approved
