Lets make a triangle 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 -&gt; 1
1,0 -&gt; 1
2,0 -&gt; 2
4,2 -&gt; 14
6,3 -&gt; 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
Jelly, 18 17 bytes

SṚ0;+Sṭ
1WWÇ⁸¡ṪṙḢ


Uses 0-based indexing.

Try it online!

How it works

1WWÇ⁸¡ṪṙḢ  Main link. Arguments: n, r

1          Set the return value to 1.
 W         Wrap; yield [1].
  W        Wrap; yield [[1]].
           This is the triangle with one row.
   Ç⁸¡     Call the helper link n times.
           Each iteration adds one row to the triangle.
      Ṫ    Tail; take the last array, i.e., the row n of the triangle.
       ṙ   Rotate row n r units to the left.
        Ḣ  Head; take the first element, i.e., entry r of row n.


SṚ0;+Sṭ    Helper link. Argument: T (triangle)

S          Take the column-wise sums, i.e., sum the ascending diagonals of the 
           centered triangle, left to right.
 Ṛ         Reverse the array of sums. The result is equal to the sums of the 
           descending diagonals of the centered triangle, also left to right.
  0;       Prepend a 0. This is required because the first element of the next row 
           doesn't have a descending diagonal.
     S     Take the column-wise sum of T.
    +      Add the ascending to the descending diagonals.