A173258
Number of compositions of n where differences between neighboring parts are in {-1,1}.
Original entry on oeis.org
1, 1, 1, 3, 2, 4, 5, 5, 7, 10, 9, 14, 16, 19, 24, 31, 35, 45, 55, 66, 84, 104, 124, 156, 192, 236, 292, 363, 444, 551, 681, 839, 1040, 1287, 1586, 1967, 2430, 3001, 3717, 4597, 5683, 7034, 8697, 10758, 13312, 16469, 20369, 25204, 31180, 38574, 47726, 59047
Offset: 0
a(3) = 3: [3], [2,1], [1,2].
a(4) = 2: [4], [1,2,1].
a(5) = 4: [5], [3,2], [2,3], [2,1,2].
a(6) = 5: [6], [3,2,1], [2,1,2,1], [1,2,3], [1,2,1,2].
-
b:= proc(n, i) option remember;
`if`(n<1 or i<1, 0, `if`(n=i, 1, add(b(n-i, i+j), j=[-1, 1])))
end:
a:= n-> `if`(n=0, 1, add(b(n, j), j=1..n)):
seq(a(n), n=0..70);
-
b[n_, i_] := b[n, i] = If[n < 1 || i < 1, 0, If[n == i, 1, Sum[b[n - i, i + j], {j, {-1, 1}}]]]; a[n_] := If[n == 0, 1, Sum[b[n, j], {j, 1, n}]]; Table[a[n], {n, 0, 70}] // Flatten (* Jean-François Alcover, Dec 13 2013, translated from Maple *)
-
step(R,n)={matrix(n, n, i, j, if(i>j, if(j>1, R[i-j, j-1]) + if(j+1<=n, R[i-j, j+1])) )}
a(n)={my(R=matid(n), t=(n==0), m=0); while(R, m++; t+=vecsum(R[n,]); R=step(R,n)); t} \\ Andrew Howroyd, Aug 23 2019
A309938
Triangle read by rows: T(n,k) is the number of compositions of n with k parts and differences all equal to 1 or -1.
Original entry on oeis.org
1, 1, 0, 1, 2, 0, 1, 0, 1, 0, 1, 2, 1, 0, 0, 1, 0, 2, 2, 0, 0, 1, 2, 1, 0, 1, 0, 0, 1, 0, 1, 4, 1, 0, 0, 0, 1, 2, 2, 0, 3, 2, 0, 0, 0, 1, 0, 1, 4, 2, 0, 1, 0, 0, 0, 1, 2, 1, 0, 3, 6, 1, 0, 0, 0, 0, 1, 0, 2, 4, 3, 0, 4, 2, 0, 0, 0, 0, 1, 2, 1, 0, 3, 8, 3, 0, 1, 0, 0, 0, 0
Offset: 1
Triangle begins:
1;
1, 0;
1, 2, 0;
1, 0, 1, 0;
1, 2, 1, 0, 0;
1, 0, 2, 2, 0, 0;
1, 2, 1, 0, 1, 0, 0;
1, 0, 1, 4, 1, 0, 0, 0;
1, 2, 2, 0, 3, 2, 0, 0, 0;
1, 0, 1, 4, 2, 0, 1, 0, 0, 0;
1, 2, 1, 0, 3, 6, 1, 0, 0, 0, 0;
1, 0, 2, 4, 3, 0, 4, 2, 0, 0, 0, 0;
1, 2, 1, 0, 3, 8, 3, 0, 1, 0, 0, 0, 0;
1, 0, 1, 4, 3, 0, 6, 8, 1, 0, 0, 0, 0, 0;
1, 2, 2, 0, 4, 10, 5, 0, 5, 2, 0, 0, 0, 0, 0;
...
For n = 6 there are a total of 5 compositions:
k = 1: (6)
k = 3: (123), (321)
k = 4: (2121), (1212)
-
b:= proc(n, i) option remember; `if`(n<1 or i<1, 0,
`if`(n=i, x, add(expand(x*b(n-i, i+j)), j=[-1, 1])))
end:
T:= n-> (p-> seq(coeff(p, x, i), i=1..n))(add(b(n, j), j=1..n)):
seq(T(n), n=1..14); # Alois P. Heinz, Jul 22 2023
-
b[n_, i_] := b[n, i] = If[n < 1 || i < 1, 0, If[n == i, x, Sum[Expand[x*b[n - i, i + j]], {j, {-1, 1}}]]];
T[n_] := CoefficientList[Sum[b[n, j], {j, 1, n}], x] // Rest // PadRight[#, n]&;
Table[T[n], {n, 1, 13}] // Flatten (* Jean-François Alcover, Sep 06 2023, after Alois P. Heinz *)
-
step(R,n)={matrix(n, n, i, j, if(i>j, if(j>1, R[i-j, j-1]) + if(j+1<=n, R[i-j, j+1])) )}
T(n)={my(v=vector(n), R=matid(n), m=0); while(R, m++; v[m]+=vecsum(R[n,]); R=step(R,n)); v}
for(n=1, 15, print(T(n)))
A364039
Triangle read by rows: T(n,k) is the number of integer compositions of n with first part k and differences between neighboring parts in {-1,1}.
Original entry on oeis.org
1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 2, 1, 0, 1, 0, 2, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 3, 2, 0, 0, 0, 0, 1, 0, 3, 2, 1, 2, 1, 0, 0, 0, 1, 0, 2, 3, 2, 1, 0, 0, 0, 0, 0, 1, 0, 3, 4, 3, 1, 1, 1, 0, 0, 0, 0, 1, 0, 4, 4, 4, 2, 1, 0, 0, 0, 0, 0, 0, 1
Offset: 0
Triangle begins:
1;
0, 1;
0, 0, 1;
0, 1, 1, 1;
0, 1, 0, 0, 1;
0, 0, 2, 1, 0, 1;
0, 2, 1, 1, 0, 0, 1;
0, 1, 1, 1, 1, 0, 0, 1;
0, 1, 3, 2, 0, 0, 0, 0, 1;
0, 3, 2, 1, 2, 1, 0, 0, 0, 1;
0, 2, 3, 2, 1, 0, 0, 0, 0, 0, 1;
...
For n = 6 there are a total of 5 compositions:
T(6,1) = 2: (123), (1212)
T(6,2) = 1: (2121)
T(6,3) = 1: (321)
T(6,6) = 1: (6)
-
T:= proc(n, i) option remember; `if`(n<1 or i<1, 0,
`if`(n=i, 1, add(T(n-i, i+j), j=[-1, 1])))
end: T(0$2):=1:
seq(seq(T(n, k), k=0..n), n=0..14); # Alois P. Heinz, Aug 08 2023
-
def A364039_rowlist(row_max):
A = []
for n in range(0,row_max+1):
A.append([])
for k in range(0,n+1):
z = 0
if n==k: z += 1
elif k > 1 and k-1 <= n-k: z += A[n-k][k-1]
if k+1 <= n-k and k != 0: z += A[n-k][k+1]
A[n].append(z)
print(A[n])
A364039_rowlist(12)
Showing 1-3 of 3 results.
Comments