Xlambda
Well-known Member
- Joined
- Mar 8, 2021
- Messages
- 860
- Office Version
- 365
- Platform
- Windows
LARGESUM sums 2 large numbers
On Fibonacci post this site was pointed to me Lambda for large numbers . This is my take using recursion. Uses this tools:
T_2RH(a,b)=LAMBDA(a,b,LET(ca,COLUMNS(a),cb,COLUMNS(b),c,ca+cb,s,SEQUENCE(,c),rs,IF(s<=ca,IF(a="","",a),INDEX(IF(b="","",b),s-ca)),rs))
!! recursive !! T_LSUM(a,i)=LAMBDA(a,i,LET(n,COLUMNS(a),x,INDEX(a,n),c,SEQUENCE(,COLUMNS(i)),y,T_2RH(x+INT(INDEX(i,1)/10),i),IF(n=1,INDEX(y,c),T_LSUM(INDEX(a,SEQUENCE(,n-1)),y))))
On Fibonacci post this site was pointed to me Lambda for large numbers . This is my take using recursion. Uses this tools:
T_2RH(a,b)=LAMBDA(a,b,LET(ca,COLUMNS(a),cb,COLUMNS(b),c,ca+cb,s,SEQUENCE(,c),rs,IF(s<=ca,IF(a="","",a),INDEX(IF(b="","",b),s-ca)),rs))
!! recursive !! T_LSUM(a,i)=LAMBDA(a,i,LET(n,COLUMNS(a),x,INDEX(a,n),c,SEQUENCE(,COLUMNS(i)),y,T_2RH(x+INT(INDEX(i,1)/10),i),IF(n=1,INDEX(y,c),T_LSUM(INDEX(a,SEQUENCE(,n-1)),y))))
Excel Formula:
=LAMBDA(a,b,
LET(ab,CHOOSE({1;2},a,b),l,LEN(ab),ml,MAX(l),x,IF(LEN(ab)<ml,REPLACE(ab,1,0,REPT(0,ml-LEN(ab))),ab),
mx,--MID(x,SEQUENCE(,ml),1),y,MMULT({1,1},mx),t,T_LSUM(y,0),
INDEX(t,1)&CONCAT(RIGHT(INDEX(t,SEQUENCE(,ml-1,2)),1))
)
)
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1:K1 | B1 | =SEQUENCE(,10) |
A2:A9 | A2 | =SEQUENCE(8) |
D2:K9 | D2 | =B2+C2 |
B3:B9 | B3 | =J2+K2 |
C3:C9 | C3 | =B3+K2 |
E11:K11,D12:K16 | E11 | =LARGESUM(C11,D11) |
B12:B16 | B12 | =LARGESUM(J11,K11) |
C12:C16 | C12 | =LARGESUM(B12,K11) |
C20:C21 | C20 | =LEN(D20) |
C22 | C22 | =FORMULATEXT(D22) |
D22 | D22 | =LARGESUM(D20,D21) |
Dynamic array formulas. |
Upvote
0