Created
May 20, 2024 20:37
-
-
Save lhem/c8e5b6ffa72aa1381d5076f734e105c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Various Implementations for extensions of BYROW | |
BYROW.N=LAMBDA(i, | |
CHOOSE(i+1,BYROW0,BYROW1,BYROW2,BYROW3,BYROW4,BYROW5) | |
); | |
// 0. REDUCE / VSTACK | |
BYROW0=LAMBDA(array,function, | |
DROP( | |
REDUCE( | |
0, | |
SEQUENCE(ROWS(array)), | |
LAMBDA(a, i, | |
VSTACK(a, function(CHOOSEROWS(array, i))) | |
) | |
), | |
1 | |
) | |
); | |
// 1. MAP / thunk | |
BYROW1=LAMBDA(array,function, | |
MAP( | |
IF(SEQUENCE(, COLUMNS(array)), | |
BYROW(array, LAMBDA(x, LAMBDA(function(x)))) | |
), | |
SEQUENCE(, COLUMNS(array)) * SEQUENCE(ROWS(array), , , 0), | |
LAMBDA(thunk, i, CHOOSECOLS(thunk(), i)) | |
) | |
); | |
// 2. Bisection | |
BYROW2 = LAMBDA(array, function, | |
IF( | |
ROWS(array) = 1, | |
function(array), | |
VSTACK( | |
BYROW2(TAKE(array, ROWS(array) / 2), function), | |
BYROW2(DROP(array, ROWS(array) / 2), function) | |
) | |
) | |
); | |
// 3. BYROW / Thunk | |
BYROW3 = LAMBDA(array, function, | |
LET( | |
thunk, LAMBDA(a, LAMBDA(a)), | |
n, ROWS(array), | |
combined, @REDUCE( | |
BYROW(array, LAMBDA(x, LAMBDA(function(x)))), | |
SEQUENCE(CEILING(LOG(n, 2), 1)), | |
LAMBDA(x, _, | |
BYROW( | |
WRAPROWS(x, 2, thunk("")), | |
LAMBDA(x, | |
thunk(VSTACK(INDEX(x, 1, 1)(), INDEX(x, 1, 2)())) | |
) | |
) | |
) | |
), | |
TAKE(combined(), n) | |
) | |
); | |
// 4. REDUCE / VSTACK - 2 Step | |
BYROW4 =LAMBDA(array,function,LET( | |
n,ROWS(array), | |
m,CEILING.MATH(n^0.5), | |
l,SEQUENCE(m,,0), | |
x,LAMBDA(i,j,function(CHOOSEROWS(array,MIN(m*i+j+1,n)))), | |
combined, | |
DROP(REDUCE(0,l,LAMBDA(a,i,VSTACK(a, | |
DROP(REDUCE(0,l,LAMBDA(a,j,VSTACK(a,x(i,j) | |
))),1) | |
))),1), | |
TAKE(combined,n)) | |
); | |
// 5. REDUCE / VSTACK - 3 Step | |
BYROW5 =LAMBDA(array,function,LET( | |
n,ROWS(array), | |
m,CEILING.MATH(POWER(n,1/3)), | |
l,SEQUENCE(m,,0), | |
x,LAMBDA(b,function(CHOOSEROWS(array,MIN(SERIESSUM(m,0,1,b)+1,n)))), | |
combined, | |
DROP(REDUCE(0,l,LAMBDA(a,i,VSTACK(a, | |
DROP(REDUCE(0,l,LAMBDA(a,j,VSTACK(a, | |
DROP(REDUCE(0,l,LAMBDA(a,k,VSTACK(a, | |
x(HSTACK(k,j,i)) | |
))),1) | |
))),1) | |
))),1), | |
TAKE(combined,n)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment