I need a formula to make 2D array of combination of a number of elements given an array of possible variables. Below is the sample input output:
ne = 2
x = {a;b;c}
out = {a,a; a,b; a,c; b,a; b,b; b,c; c,a; c,b;, c,c}
ne is number of elements as integer, x is list of variables as 1d array of any length. I would like to have formula without MAKEARRAY, LAMBDA or other slow functions. This is supposed to be an easy combinatoric problem, but I can't find elegant solution. Below is my attempt:
=LET(ne,A1,x,B1:B3,nx,COUNTA(x),i,SEQUENCE(nx^ne,ne,0),r,INT(i/ne)+1,c,MOD(i,ne)+1,comb,TEXT(BASE(SEQUENCE(nx^ne,,0),nx),REPT("0",ne)),INDEX(x,VALUE(MID(INDEX(comb,r),c,1))+1))
It works but too complicated.
Could anyone help? Or maybe someone has made the lambda function in lambda sub-forum? Thanks in advance.
ne = 2
x = {a;b;c}
out = {a,a; a,b; a,c; b,a; b,b; b,c; c,a; c,b;, c,c}
ne is number of elements as integer, x is list of variables as 1d array of any length. I would like to have formula without MAKEARRAY, LAMBDA or other slow functions. This is supposed to be an easy combinatoric problem, but I can't find elegant solution. Below is my attempt:
=LET(ne,A1,x,B1:B3,nx,COUNTA(x),i,SEQUENCE(nx^ne,ne,0),r,INT(i/ne)+1,c,MOD(i,ne)+1,comb,TEXT(BASE(SEQUENCE(nx^ne,,0),nx),REPT("0",ne)),INDEX(x,VALUE(MID(INDEX(comb,r),c,1))+1))
It works but too complicated.
Could anyone help? Or maybe someone has made the lambda function in lambda sub-forum? Thanks in advance.