Most people are familiar with Pascal's triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Pascal's triangle is an automaton where the value of a cell is the sum of the cells to the upper left and upper right. Now we are going to define a similar triangle. Instead of just taking the cells to the upper left and the upper right we are going to take all the cells along two infinite lines extending to the upper left and upper right. Just like Pascal's triangle we start with a single 1
padded infinitely by zeros and build downwards from there.
For example to calculate the cell denoted with an x
1
1 1
2 2 2
4 5 5 4
x
We would sum the following cells
.
. .
2 . 2
. 5 5 .
x
Making our new cell 14
.
Task
Given a row number (n), and distance from the left (r) calculate and output the rth non-zero entry from the left on the nth row. (the equivalent on Pascal's triangle is nCr). You may assume that r is less than n.
This is code-golf, the goal is to minimize the number of bytes in your solution.
Test cases
0,0 -> 1
1,0 -> 1
2,0 -> 2
4,2 -> 14
6,3 -> 106
Here's the first couple rows in triangle form:
1
1 1
2 2 2
4 5 5 4
8 12 14 12 8
16 28 37 37 28 16
32 64 94 106 94 64 32
64 144 232 289 289 232 144 64
128 320 560 760 838 760 560 320 128