Skip to main content
added 277 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

JavaScript (ES6), 83 bytes

f= n=>[...Array(n+--n)].map(g=(j=n,i,a)=>j--?g(j,i-1)+g(j,i+1)+(a?g(j,i,a):0):i-n?0:1)
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>

1-indexing cost me a byte. Explanation: g(j-1,i-1)+g(j-1,i+1) recursively calculates Pascal's triangle until it reaches the first row, which is the base case. To obtain column sums, I use the fact that map actually passes a third parameter, so there is an extra recursive step when this is the case.

JavaScript (ES6), 83 bytes

f= n=>[...Array(n+--n)].map(g=(j=n,i,a)=>j--?g(j,i-1)+g(j,i+1)+(a?g(j,i,a):0):i-n?0:1)
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>

1-indexing cost me a byte.

JavaScript (ES6), 83 bytes

f= n=>[...Array(n+--n)].map(g=(j=n,i,a)=>j--?g(j,i-1)+g(j,i+1)+(a?g(j,i,a):0):i-n?0:1)
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>

1-indexing cost me a byte. Explanation: g(j-1,i-1)+g(j-1,i+1) recursively calculates Pascal's triangle until it reaches the first row, which is the base case. To obtain column sums, I use the fact that map actually passes a third parameter, so there is an extra recursive step when this is the case.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

JavaScript (ES6), 83 bytes

f= n=>[...Array(n+--n)].map(g=(j=n,i,a)=>j--?g(j,i-1)+g(j,i+1)+(a?g(j,i,a):0):i-n?0:1)
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>

1-indexing cost me a byte.