- 50.9k
- 11
- 133
- 364
Jelly, 22 bytes
’1l·_+1l·’}\ð‘ị3ðṛ?
J’Ç€
Horrible recursive definition, I'm sure there's a better approach. Full program.Here 's a modified version to run as a test suite.
How it works
We just implement
$$T(n,k) = \begin{cases} a_n & \text{if } k = 0 \\ T(n-1,n-k) + T(n, k-1) & \text{otherwise} \end{cases}$$
then calculate \$T(i,i)\$ for each index \$i\$ of \$a\$
The first line defines \$T(n,k)\$, and the second calculates \$T(i,i)\$ for each index \$i\$.
’1l·_+1l·’}\ð‘ị3ðṛ? - Helper link. T(n,k).
ṛ? - If k:
ð - Then:
’ - n-1
_ - n-k
1l· - T(n-1, n-k)
\ - Last two links as a dyad g(n,k):
’} - k-1
1l· - T(n, k-1)
+ - T(n-1, n-k) + T(n, k-1)
ð - Else:
‘ - n+1 (due to Jelly's 1 indexing)
ị3 - Index into a
J’Ç€ - Main link. Takes a on the left
J - Indices of a
’ - Decrement to 0 index
€ - Over each index i:
Ç - Yield T(i,i)
Jelly, 22 bytes
’1l·_+1l·’}\ð‘ị3ðṛ?
J’Ç€
Horrible recursive definition, I'm sure there's a better approach. Full program.
Jelly, 22 bytes
’1l·_+1l·’}\ð‘ị3ðṛ?
J’Ç€
Horrible recursive definition, I'm sure there's a better approach. Full program.Here 's a modified version to run as a test suite.
How it works
We just implement
$$T(n,k) = \begin{cases} a_n & \text{if } k = 0 \\ T(n-1,n-k) + T(n, k-1) & \text{otherwise} \end{cases}$$
then calculate \$T(i,i)\$ for each index \$i\$ of \$a\$
The first line defines \$T(n,k)\$, and the second calculates \$T(i,i)\$ for each index \$i\$.
’1l·_+1l·’}\ð‘ị3ðṛ? - Helper link. T(n,k).
ṛ? - If k:
ð - Then:
’ - n-1
_ - n-k
1l· - T(n-1, n-k)
\ - Last two links as a dyad g(n,k):
’} - k-1
1l· - T(n, k-1)
+ - T(n-1, n-k) + T(n, k-1)
ð - Else:
‘ - n+1 (due to Jelly's 1 indexing)
ị3 - Index into a
J’Ç€ - Main link. Takes a on the left
J - Indices of a
’ - Decrement to 0 index
€ - Over each index i:
Ç - Yield T(i,i)
Jelly, 22 bytes
’1l·_+1l·’}\ð‘ị3ðṛ?
J’Ç€
Horrible recursive definition, I'm sure there's a better approach. Full program.