Pascal's triangle: Difference between revisions

m
→‎Excel LAMBDA: Preferred a non recursive definition of the grid.
m (→‎Excel LAMBDA: Preferred a non recursive definition of the grid.)
Line 2,289:
|}
 
Or defining the whole triangle recursively as a single grid, by binding the name TRIANGLE to an additional lambda, (and using the built-in IFNA function to fill #N/A cells in the grid with empty strings):
 
<lang lisp>TRIANGLE
=LAMBDA(n,
IF LET(1 = n,
ixs, SEQUENCE(n, n, 0, 1),
APPENDROWSx, MOD(ixs, n),
y, QUOTIENT(ixs, TRIANGLE(n - 1),
)IF(x <= y,
PASCALBINCOEFF(ny)(x),
) ""
)
)</lang>
 
and also assuming the following generic binding in the Name Manager of the Excel workbook:
 
<lang lisp>APPENDROWS
=LAMBDA(xs,
LAMBDA(ys,
LET(
nx, ROWS(xs),
rowIndexes, SEQUENCE(nx + ROWS(ys)),
colIndexes, SEQUENCE(
1,
MAX(COLUMNS(xs), COLUMNS(ys))
),
 
IFERROR(
IF(rowIndexes <= nx,
INDEX(xs, rowIndexes, colIndexes),
INDEX(ys, rowIndexes - nx, colIndexes)
),
NA()
)
)
)
9,659

edits