A338614
Number of permutations p of [n] such that |p(i) - p(i-1)| <= 3 and |p(i) - p(i-2)| <= 4.
Original entry on oeis.org
1, 1, 2, 6, 24, 72, 124, 210, 394, 810, 1652, 3168, 5816, 10640, 19794, 37292, 70298, 131618, 245146, 456430, 851670, 1592008, 2976326, 5559808, 10379010, 19374184, 36175422, 67562524, 126185322, 235650426, 440038528
Offset: 0
-
b:= proc(s, x, y) option remember; `if`(s={}, 1, add(
`if`((x=0 or abs(x-j)<=4) and (y=0 or abs(y-j)<=3),
b(s minus {j}, y, j), 0), j=s))
end:
a:= n-> b({$1..n}, 0$2):
seq(a(n), n=0..20);
A348534
Number of permutations p of [n] whose absolute differences between consecutive elements yield up-down sequences.
Original entry on oeis.org
1, 1, 2, 2, 8, 20, 82, 326, 1678, 8776, 54804, 357910, 2646340, 20551986, 176420758, 1586656630, 15504954504, 158675287132, 1738817196038, 19931418239724, 242312687882510
Offset: 0
a(0) = 1: (), the empty permutation.
a(1) = 1: 1.
a(2) = 2: 12, 21.
a(3) = 2: 213, 231.
a(4) = 8: 1243, 2134, 2143, 2413, 3142, 3412, 3421, 4312.
a(5) = 20: 12435, 12453, 21435, 21453, 23541, 31425, 31452, 31542, 32451, 32541, 34125, 34215, 35124, 35214, 35241, 43125, 45213, 45231, 54213, 54231.
a(6) = 82: 124356, 124365, 125364, 125634, ..., 652143, 652413, 653412, 653421.
-
b:= proc(s, x, y) option remember; (n-> `if`(n=0, 1, add((d->
`if`(x=0 or n::even and xd, b(s minus {j},
`if`(y=0, 0, d), j), 0))(abs(y-j)), j=s)))(nops(s))
end:
a:= n-> b({$1..n}, 0$2):
seq(a(n), n=0..12);
-
b[s_, x_, y_] := b[s, x, y] = Function[n, If[n == 0, 1, Sum[Function[d,
If[x == 0 || EvenQ[n] && x < d || OddQ[n] && x > d, b[s ~Complement~
{j}, If[y == 0, 0, d], j], 0]][Abs[y - j]], {j, s}]]][Length[s]];
a[n_] := b[Range[n], 0, 0];
Table[a[n], {n, 0, 12}] (* Jean-François Alcover, Mar 07 2022, after Alois P. Heinz *)
Showing 1-2 of 2 results.
Comments