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-6 of 6 results.

A002467 The game of Mousetrap with n cards (given n letters and n envelopes, how many ways are there to fill the envelopes so that at least one letter goes into its right envelope?).

Original entry on oeis.org

0, 1, 1, 4, 15, 76, 455, 3186, 25487, 229384, 2293839, 25232230, 302786759, 3936227868, 55107190151, 826607852266, 13225725636255, 224837335816336, 4047072044694047, 76894368849186894, 1537887376983737879, 32295634916658495460, 710503968166486900119
Offset: 0

Views

Author

Keywords

Comments

a(n) is the number of permutations in the symmetric group S_n that have a fixed point, i.e., they are not derangements (A000166). - Ahmed Fares (ahmedfares(AT)my-deja.com), May 08 2001
a(n+1)=p(n+1) where p(x) is the unique degree-n polynomial such that p(k)=k! for k=0,1,...,n. - Michael Somos, Oct 07 2003
The termwise sum of this sequence and A000166 gives the factorial numbers. - D. G. Rogers, Aug 26 2006, Jan 06 2008
a(n) is the number of deco polyominoes of height n and having in the last column an odd number of cells. A deco polyomino is a directed column-convex polyomino in which the height, measured along the diagonal, is attained only in the last column. Example: a(2)=1 because the horizontal domino is the only deco polyomino of height 2 having an odd number of cells in the last column. - Emeric Deutsch, May 08 2008
Starting (1, 4, 15, 76, 455, ...) = eigensequence of triangle A127899 (unsigned). - Gary W. Adamson, Dec 29 2008
(n-1) | a(n), hence a(n) is never prime. - Jonathan Vos Post, Mar 25 2009
a(n) is the number of permutations of [n] that have at least one fixed point = number of positive terms in n-th row of the triangle in A170942, n > 0. - Reinhard Zumkeller, Mar 29 2012
Numerator of partial sum of alternating harmonic series, provided that the denominator is n!. - Richard Locke Peterson, May 11 2020
a(n) is the number of terms in the polynomial expansion of the determinant of a n X n matrix that contains at least one diagonal element. - Adam Wang, May 28 2025

Examples

			G.f. = x + x^2 + 4*x^3 + 15*x^4 + 76*x^5 + 455*x^6 + 3186*x^7 + 25487*x^8 + ...
		

References

  • R. K. Guy, Unsolved Problems Number Theory, E37.
  • R. K. Guy and R. J. Nowakowski, "Mousetrap," in D. Miklos, V. T. Sos and T. Szonyi, eds., Combinatorics, Paul Erdős is Eighty. Bolyai Society Math. Studies, Vol. 1, pp. 193-206, 1993.
  • N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Row sums of A068106.
Column k=1 of A293211.
Column k=0 of A299789, A306234, and of A324362.

Programs

  • Maple
    a := proc(n) -add((-1)^i*binomial(n, i)*(n-i)!, i=1..n) end;
    a := n->-n!*add((-1)^k/k!, k=1..n): seq(a(n), n=0..20); # Zerinvary Lajos, May 25 2007
    a := n -> simplify(GAMMA(n+1) - GAMMA(n+1, -1)*exp(-1)):
    seq(a(n), n=0..20); # Peter Luschny, Feb 28 2017
  • Mathematica
    Denominator[k=1; NestList[1+1/(k++ #1)&,1,12]] (* Wouter Meeussen, Mar 24 2007 *)
    a[ n_] := If[ n < 0, 0, n! - Subfactorial[n]] (* Michael Somos, Jan 25 2014 *)
    a[ n_] := If[ n < 1, 0, n! - Round[ n! / E]] (* Michael Somos, Jan 25 2014 *)
    a[ n_] := If[ n < 0, 0, n! - (-1)^n HypergeometricPFQ[ {- n, 1}, {}, 1]](* Michael Somos, Jan 25 2014 *)
    a[ n_] := If[ n < 0, 0, n! SeriesCoefficient[ (1 - Exp[ -x] ) / (1 - x), {x, 0, n}]] (* Michael Somos, Jan 25 2014 *)
    RecurrenceTable[{a[n] == (n - 1) ( a[n - 1] + a[n - 2]), a[0] == 0, a[1] == 1}, a[n], {n, 20}] (* Ray Chandler, Jul 30 2015 *)
  • PARI
    {a(n) = if( n<1, 0, n * a(n-1) - (-1)^n)} /* Michael Somos, Mar 24 2003 */
    
  • PARI
    {a(n) = if( n<0, 0, n! * polcoeff( (1 - exp( -x + x * O(x^n))) / (1 - x), n))} /* Michael Somos, Mar 24 2003 */
    
  • PARI
    a(n) = if(n<1,0,subst(polinterpolate(vector(n,k,(k-1)!)),x,n+1))
    
  • PARI
    A002467(n) = if(n<1, 0, n*A002467(n-1)-(-1)^n); \\ Joerg Arndt, Apr 22 2013

Formula

a(n) = n! - A000166(n) = A000142(n) - A000166(n).
E.g.f.: (1 - exp(-x)) / (1 - x). - Michael Somos, Aug 11 1999
a(n) = (n-1)*(a(n-1) + a(n-2)), n > 1; a(1) = 1. - Michael Somos, Aug 11 1999
a(n) = n*a(n-1) - (-1)^n. - Michael Somos, Aug 11 1999
a(0) = 0, a(n) = floor(n!(e-1)/e + 1/2) for n > 0. - Michael Somos, Aug 11 1999
a(n) = - n! * Sum_{i=1..n} (-1)^i/i!. Limit_{n->infinity} a(n)/n! = 1 - 1/e. - Gerald McGarvey, Jun 08 2004
Inverse binomial transform of A002627. - Ross La Haye, Sep 21 2004
a(n) = (n-1)*(a(n-1) + a(n-2)), n > 1. - Gary Detlefs, Apr 11 2010
a(n) = n! - floor((n!+1)/e), n > 0. - Gary Detlefs, Apr 11 2010
For n > 0, a(n) = {(1-1/exp(1))*n!}, where {x} is the nearest integer. - Simon Plouffe, conjectured March 1993, added Feb 17 2011
0 = a(n) * (a(n+1) + a(n+2) - a(n+3)) + a(n+1) * (a(n+1) + 2*a(n+2) - a(n+3)) + a(n+2) * (a(n+2)) if n >= 0. - Michael Somos, Jan 25 2014
a(n) = Gamma(n+1) - Gamma(n+1, -1)*exp(-1). - Peter Luschny, Feb 28 2017
a(n) = Sum_{k=0..n-1} A047920(n-1,k). - Alois P. Heinz, Sep 01 2021

A130152 Triangle read by rows: T(n,k) = number of permutations p of [n] such that max(|p(i)-i|)=k (n>=1, 0<=k<=n-1).

Original entry on oeis.org

1, 1, 1, 1, 2, 3, 1, 4, 9, 10, 1, 7, 23, 47, 42, 1, 12, 60, 157, 274, 216, 1, 20, 151, 503, 1227, 1818, 1320, 1, 33, 366, 1669, 4833, 10402, 13656, 9360, 1, 54, 877, 5472, 18827, 50879, 96090, 115080, 75600, 1, 88, 2088, 17531, 75693, 234061, 569602, 966456, 1077840, 685440, 1, 143, 4937, 55135, 304900, 1076807, 3111243, 6791994, 10553640, 11123280, 6894720
Offset: 1

Views

Author

Emeric Deutsch, May 27 2007

Keywords

Comments

Row sums are the factorials. T(n,n) = (n-2)!*(2n-3) = A007680(n-2) (for n>=2). T(n,1) = Fibonacci(n+1)-1 = A000071(n+1). Sum_{k=0..n-1} k*T(n,k) = A130153(n). For the statistic max(p(i)-i) see A056151.

Examples

			T(4,1) = 4 because we have 1243, 1324, 2134 and 2143.
Triangle starts:
  1;
  1,  1;
  1,  2,  3;
  1,  4,  9,  10;
  1,  7, 23,  47,  42;
  1, 12, 60, 157, 274, 216;
  ...
		

Crossrefs

Row sums give A000142.
T(n,floor(n/2)) gives A323807.

Programs

  • Maple
    with(combinat): for n from 1 to 7 do P:=permute(n): for i from 0 to n-1 do ct[i]:=0 od: for j from 1 to n! do if max(seq(abs(P[j][i]-i),i=1..n))=0 then ct[0]:=ct[0]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=1 then ct[1]:=ct[1]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=2 then ct[2]:=ct[2]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=3 then ct[3]:=ct[3]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=4 then ct[4]:=ct[4]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=5 then ct[5]:=ct[5]+1 elif max(seq(abs(P[j][i]-i),i=1..n))=6 then ct[6]:=ct[6]+1 else fi od: a[n]:=seq(ct[i],i=0..n-1): od: for n from 1 to 7 do a[n] od; # a cumbersome program to obtain, by straightforward counting, the first 7 rows of the triangle
    n := 8: st := proc (p) max(seq(abs(p[j]-j), j = 1 .. nops(p))) end proc: with(combinat): P := permute(n): f := sort(add(t^st(P[i]), i = 1 .. factorial(n))); # program gives the row generating polynomial for the specified n - Emeric Deutsch, Aug 13 2009
    # second Maple program:
    b:= proc(s) option remember; (n-> `if`(n=0, 1, add((p-> add(
          coeff(p, x, i)*x^max(i, abs(n-j)), i=0..degree(p)))(
            b(s minus {j})), j=s)))(nops(s))
        end:
    T:= n-> (p-> seq(coeff(p, x, i), i=0..n-1))(b({$1..n})):
    seq(T(n), n=1..10);  # Alois P. Heinz, Jan 21 2019
    # third Maple program:
    A:= proc(n, k) option remember; LinearAlgebra[Permanent](
          Matrix(n, (i, j)-> `if`(abs(i-j)<=k, 1, 0)))
        end:
    T:= (n, k)-> A(n, k)-A(n, k-1):
    seq(seq(T(n, k), k=0..n-1), n=1..10);  # Alois P. Heinz, Jan 22 2019
  • Mathematica
    (* from second Maple program: *)
    b[s_List] := b[s] = Function[n, If[n == 0, 1, Sum[Function[p, Sum[ Coefficient[p, x, i]*x^Max[i, Abs[n - j]], {i, 0, Exponent[p, x]}]][b[s ~Complement~ {j}]], {j, s}]]][Length[s]];
    T[n_] := Function[p, Table[Coefficient[p, x, i], {i, 0, n-1}]][b[Range[n]] ];
    Table[T[n], {n, 1, 11}] // Flatten
    (* from third Maple program: *)
    A[n_, k_] := A[n, k] = Permanent[Table[If[Abs[i-j] <= k, 1, 0], {i, 1, n}, {j, 1, n}]];
    T[n_, k_] := A[n, k] - A[n, k - 1];
    Table[Table[T[n, k], {k, 0, n - 1}], {n, 1, 11}] // Flatten (* Jean-François Alcover, Dec 06 2019, after Alois P. Heinz *)

Formula

T(n,k) = A306209(n,k) - A306209(n,k-1) for k > 0, T(n,0) = 1. - Alois P. Heinz, Jan 29 2019

Extensions

More terms from R. J. Mathar, Oct 15 2007

A296050 Number of permutations p of [n] such that min_{j=1..n} |p(j)-j| = 1.

Original entry on oeis.org

0, 0, 1, 2, 8, 40, 236, 1648, 13125, 117794, 1175224, 12903874, 154615096, 2007498192, 28075470833, 420753819282, 6726830163592, 114278495205524, 2055782983578788, 39039148388975552, 780412763620655061, 16381683795665956242, 360258256118419518680, 8283042472303599966974
Offset: 0

Views

Author

Alois P. Heinz, Jan 21 2019

Keywords

Examples

			a(2) = 1: 21.
a(3) = 2: 231, 312.
a(4) = 8: 2143, 2341, 2413, 3142, 3421, 4123, 4312, 4321.
a(5) = 40: 21453, 21534, 23154, 23451, 23514, 24153, 24513, 24531, 25134, 25413, 25431, 31254, 31452, 31524, 34152, 34251, 35124, 35214, 35412, 35421, 41253, 41523, 41532, 43152, 43251, 43512, 43521, 45132, 45213, 45231, 51234, 51423, 51432, 53124, 53214, 53412, 53421, 54132, 54213, 54231.
		

Crossrefs

Programs

  • Maple
    b:= proc(s, k) option remember; (n-> `if`(n=0, `if`(k=1, 1, 0), add(
          `if`(n=j, 0, b(s minus {j}, min(k, abs(n-j)))), j=s)))(nops(s))
        end:
    a:= n-> b({$1..n}, n):
    seq(a(n), n=0..14);
    # second Maple program:
    a:= n-> (f-> f(1)-f(2))(k-> `if`(n=0, 1, LinearAlgebra[Permanent](
            Matrix(n, (i, j)-> `if`(abs(i-j)>=k, 1, 0))))):
    seq(a(n), n=0..14);
    # third Maple program:
    g:= proc(n) g(n):= `if`(n<2, 1-n, (n-1)*(g(n-1)+g(n-2))) end:
    h:= proc(n) h(n):= `if`(n<7, [1, 0$3, 1, 4, 29][n+1], n*h(n-1)+4*h(n-2)
          -3*(n-3)*h(n-3)+(n-4)*h(n-4)+2*(n-5)*h(n-5)-(n-7)*h(n-6)-h(n-7))
        end:
    a:= n-> g(n)-h(n):
    seq(a(n), n=0..25);
  • Mathematica
    g[n_] := g[n] = If[n < 2, 1-n, (n-1)(g[n-1] + g[n-2])];
    h[n_] := h[n] = If[n < 7, {1, 0, 0, 0, 1, 4, 29}[[n+1]],
         n h[n-1] + 4h[n-2] - 3(n-3)h[n-3] + (n-4)h[n-4] +
         2(n-5)h[n-5] - (n-7)h[n-6] - h[n-7]];
    a[n_] := g[n] - h[n];
    Table[a[n], {n, 0, 25}] (* Jean-François Alcover, Aug 30 2021, after third Maple program *)

Formula

a(n) = A000142(n) - A001883(n) - A002467(n).
a(n) = A000166(n) - A001883(n).
a(n) = Sum_{k=1..n} A323671(n,k).
a(n) is odd <=> n in { A016933 }.
a(n) is even <=> n in { A047252 }.

A306543 Number T(n,k) of permutations p of [n] such that |p(j)-j| >= k (for all j in [n]); triangle T(n,k), n >= 0, 0 <= k <= floor(n/2), read by rows.

Original entry on oeis.org

1, 1, 2, 1, 6, 2, 24, 9, 1, 120, 44, 4, 720, 265, 29, 1, 5040, 1854, 206, 8, 40320, 14833, 1708, 112, 1, 362880, 133496, 15702, 1168, 16, 3628800, 1334961, 159737, 13365, 436, 1, 39916800, 14684570, 1780696, 159414, 6984, 32, 479001600, 176214841, 21599745, 2036488, 114124, 1708, 1
Offset: 0

Views

Author

Alois P. Heinz, Feb 22 2019

Keywords

Examples

			Triangle T(n,k) begins:
          1;
          1;
          2,         1;
          6,         2;
         24,         9,        1;
        120,        44,        4;
        720,       265,       29,       1;
       5040,      1854,      206,       8;
      40320,     14833,     1708,     112,      1;
     362880,    133496,    15702,    1168,     16;
    3628800,   1334961,   159737,   13365,    436,    1;
   39916800,  14684570,  1780696,  159414,   6984,   32;
  479001600, 176214841, 21599745, 2036488, 114124, 1708, 1;
  ...
		

Crossrefs

Columns k=0-6 give (offsets may differ): A000142, A000166, A001883, A075851, A075852, A183242, A183243.
T(2n,n) gives A000012.
T(2n+1,n) gives A000079.
T(2n+2,n) gives A183245 for n > 0.
T(2n+3,n) gives A183246 for n > 0.
T(2n+4,n) gives A183247 for n > 0.

Programs

  • Maple
    T:= proc(n, k) option remember; `if`(n=0, 1, LinearAlgebra[
          Permanent](Matrix(n, (i, j)-> `if`(abs(i-j)>=k, 1, 0))))
        end:
    seq(seq(T(n, k), k=0..floor(n/2)), n=0..12);
  • Mathematica
    T[n_, k_] := T[n, k] = If[n==0, 1, Permanent[Table[
         If[Abs[i-j] >= k, 1, 0], {i, n}, {j, n}]]];
    Table[Table[T[n, k], {k, 0, Floor[n/2]}], {n, 0, 12}] // Flatten (* Jean-François Alcover, Mar 26 2021, after Alois P. Heinz *)

Formula

T(n,k) = Sum_{j=k..floor(n/2)} A299789(n,j) for n > 0.

A306545 Number of permutations p of [2n+2] such that min_{j=1..2n+2} |p(j)-j| = n.

Original entry on oeis.org

1, 8, 28, 111, 435, 1707, 6723, 26571, 105315, 418347, 1664643, 6632331, 26450595, 105566187, 421556163, 1684098891, 6730018275, 26900941227, 107546369283, 430013290251, 1719536600355, 6876596719467, 27501737832003, 109993004190411, 439930175348835
Offset: 0

Views

Author

Alois P. Heinz, Feb 22 2019

Keywords

Examples

			a(1) = 8: 2143, 2341, 2413, 3142, 3421, 4123, 4312, 4321.
		

Crossrefs

Cf. A299789.

Formula

G.f.: (17*x^4-27*x^3+17*x^2-1)/(12*x^3-19*x^2+8*x-1).
a(n) = A299789(2n+2,n).

A129118 For each permutation p of {1,2,...,n} define minabsjump(p) = min(|p(i) - i|, 1<=i<=n); a(n) is the sum of minabsjumps of all p.

Original entry on oeis.org

0, 1, 2, 10, 48, 295, 2068, 16654, 150382, 1508500, 16631696, 199966907, 2603709640, 36501212971, 548150650582, 8779185528284, 149376644391508, 2690852138104504, 51161190374132154, 1023850096381041159, 21512688329462044264
Offset: 1

Views

Author

Keywords

Crossrefs

Programs

  • Maple
    n:=8; with(combinat); P:=permute(n); ct:= 0; for j to factorial(n) do ct:= ct+min(seq(abs(P[j][i]-i),i=1..n)) end do: ct; # yields a(n) for the specified n - Emeric Deutsch, Aug 24 2007
    # second Maple program:
    b:= proc(s) option remember; (n-> `if`(n=1, x^(s[]-1), add((p->
          add(coeff(p, x, i)*x^min(i, abs(n-j)), i=0..degree(p)))(
            b(s minus {j})), j=s)))(nops(s))
        end:
    a:= n-> (p-> add(coeff(p, x, i)*i, i=1..n-1))(b({$1..n})):
    seq(a(n), n=1..15);  # Alois P. Heinz, Jan 21 2019
  • Mathematica
    b[s_] := b[s] = Function[n, If[n == 1, x^(s - 1), Sum[Function[p, Sum[ SeriesCoefficient[p, {x, 0, i}]*x^Min[i, Abs[n - j]], {i, 0, Exponent[p, x]}]][b[s ~Complement~ {j}]], {j, s}]]][Length[s]] // Expand;
    a[n_] := a[n] = If[n == 1, 0, Function[p, Sum[SeriesCoefficient[p, {x, 0, i}]*i, {i, 1, n - 1}]][b[Range[n]][[1]]]];
    Table[Print[n, " ", a[n]]; a[n], {n, 1, 12}] (* Jean-François Alcover, May 21 2020, after 2nd Maple program *)

Formula

a(n) = Sum_{k=1..floor(n/2)} k * A299789(n,k). - Alois P. Heinz, Jan 21 2019

Extensions

One more term from Emeric Deutsch, Aug 24 2007
a(11)-a(13) from R. J. Mathar, Nov 01 2007
a(14) from Donovan Johnson, Sep 24 2010
a(15)-a(21) from Alois P. Heinz, Jan 21 2019
Showing 1-6 of 6 results.