ARRANGEMENTS

=ARRANGEMENTS(a,t,c)

a
array
t
type argument,"pa", permutations with repetitions; "p" permutations w/o repet. ; "ca", combinations with repet. ; "c", combinations w/o repet.
c
number_chosen

Combinatorics study, permutations, combinations w or w/o repetitions, all in one function.

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
ARRANGEMENTS Extracts all permutations or combinations, with or without repetitions, of all elements of an array, by a number chosen.
Study inspired by latest MrExcel's YT (15aug21) Excel All Combinations Using Power Query - 2424
This is the first draft I came with, of course, the recursion way deserves first place. There are 2 other approaches, one using AFUSBYROW/BYCOL functions, and the other using new functions.
Calls 3 tool lambdas, 1 non recursive and 2 recursive (no risk to reach limitations, recursion takes place on the "short" direction, the columns one) . The recursive ones were created with ease using the ARF recursive kits concepts. Also, both recursive ones can be used as standalone lambdas, T_P is filtering an array by rows with no dups, and T_CA is filtering an array by rows that are in ascending order. The challenge was to do this by columns iterations and not by rows iteration (too many).
For ARRANGEMENTS function we use them to create the index patterns for extracting array's elements as are required. T_PA (non-recursive) creates the index pattern for permutations with repetitions, Once we have that, T_P (recursive) creates the index pattern for permutations without repetitions T_P(T_PA), T_CA creates the patterns for combinations with repetitions T_CA(T_PA), and for combinations without repetitions we use the same T_CA but this time, as input, we use T_P, T_CA(T_P). Calculation time for arrays having 1M rows 1 to 3 seconds.
T_PA(n,c)=LAMBDA(n,c,MOD(ROUNDUP(SEQUENCE(n^c)/n^(c-SEQUENCE(,c)),0)-1,n)+1) where n: number ; c: number chosen
T_P(a,[ai],[ i ] )=LAMBDA(a,[ai],[ i ],LET(n,COLUMNS(a),j,IF(i="",n,i),x,INDEX(a,,j),IF(j=0,FILTER(a,MMULT(ai,SEQUENCE( n)^0)=n),T_P(a,ai+(x=a),j-1)))) !! recursive !!
T_CA(a,[ai],[ i ])=LAMBDA(a,[ai],[ i ],LET(n,COLUMNS(a),j,IF(i="",1,i),aj,IF(ai="",1,ai),x,INDEX(a,,j),IF(j=n,FILTER(a,aj),T_CA(a,aj*(x<=INDEX(a,,j+1)),j+1))))
!! recursive !! where a:array, ai,i,omitted

Excel Formula:
=LAMBDA(a,t,c,
    IF(AND(t<>{"p","pa","c","ca"}),"check type",
      LET(k,MAX(1,c),x,AFLAT(a),n,ROWS(x),IF(AND(OR(t={"p","c"}),k>n),"nr chosen>n !",LET(y,T_PA(n,k),
       SWITCH(t,"pa",INDEX(x,y),"p",INDEX(x,T_P(y)),"ca",INDEX(x,T_CA(y)),"c",LET(z,T_P(y),w,T_CA(z),INDEX(x,w))))))
    )
)
LAMBDA 1.1.1.xlsx
ABCDEFGHIJKLMNO
1Introduction: Combinatorics Excel functions:
21,) PERMUTATIONA Returns the number of permutations for a given number of objects (with repetitions) that can be selected from the total objects.
3 - PERMUTATIONA(number, number-chosen); "nc" or "c" (number chosen) can be >=n (number of elements/objects) ; order is important; PA=n^nc
42.) PERMUT Returns the number of permutations for a given number of objects (no repetitions) that can be selected from the total objects.
5- PERMUT(number, number_chosen); if nc>n returns #NUM! error; also called arrangements; order is important ;P=n!/(n-nc)!
63.) COMBINA Returns the number of combinations (with repetitions) for a given number of items.
7- COMBINA(number, number_chosen) ; nc can be > n; order is not important; CA=(n+nc-1)!/(nc!*(n-1)!)
84.) COMBIN Returns the number of combinations (no repetitions) for a given number of items.
9- COMBINA(number, number_chosen) ; nc can be > n; order is not important; C=P/nc! or C=n!/(nc!*(n-nc)!)
10What ARRANGEMENTS does is "printing" or extracting all this numbers of permutations or combinations, given the object array "a" and the number_chosen "c",
11for all types "t" above : "pa" for 1.) , "p" for 2.) , "ca" for 3.) ,"c" for 4.)
12
13input n:7Table of values returned by all functions for an array of n objects ,nc [1,10]
14
15function\nc12345678910
161,) PERMUTATIONA749343240116807117649823543576480140353607282475249
172,) PERMUT742210840252050405040#NUM!#NUM!#NUM!
183.) COMBINA728842104629241716300350058008
194.) COMBIN72135352171#NUM!#NUM!#NUM!
20
21Note:It is easy to run out of "printing" real estate in an excel spreadsheet for small arrays of objects
22
ARR post 1
Cell Formulas
RangeFormula
C15:L15C15=SEQUENCE(,10)
C16:L16C16=PERMUTATIONA(C13,C15#)
C17:L17C17=PERMUT(C13,C15#)
C18:L18C18=COMBINA(C13,C15#)
C19:L19C19=COMBIN(C13,C15#)
Dynamic array formulas.
 
Upvote 0
ExcelIsFun Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRS
1Task: Sample points of throwing 3 dice that togheter sum 13
22nd scenario - no repetitions, order is important (type argument t=p)
3=PERMUT(6,3)=ARRANGEMENTS(SEQUENCE(6),"p",3)
4120↓↓=BYROW(D6#,LAMBDA(x,SUM(x)))
5=ROWS(D6#)↓↓↓↓=FILTER(D6#,H6#=13)=UNICHAR(J6#+9855)
61201236256how many?
71247265=ROWS(J6#)
8=SEQUENCE(6,,9856)125834612
9↓↓=UNICHAR(A10#)1269364
1098561326436
1198571348463
1298581359526
13985913610562
1498601427625
1598611438634
1614510643
1714611652
181528
191539
2015410
2115612
221629
2316310
2416411
2516512
262136
272147
282158
292169
302316
312349
3223510
3323611
342417
352439
3624511
3724612
382518
3925310
4025411
4125613
422619
4326311
4426412
4526513
463126
473148
483159
4931610
503216
513249
5232510
5332611
543418
553429
5634512
5734613
583519
5935210
6035412down to 120 rows
6135614↓↓↓↓↓↓↓↓↓↓
6236110
DICE 2
Cell Formulas
RangeFormula
A3,B9,R7,J5,N5,A5A3=FORMULATEXT(A4)
D3D3=FORMULATEXT(D6)
A4A4=PERMUT(6,3)
H4,A8H4=FORMULATEXT(H6)
A6A6=ROWS(D6#)
D6:F125D6=ARRANGEMENTS(SEQUENCE(6),"p",3)
H6:H125H6=BYROW(D6#,LAMBDA(x,SUM(x)))
J6:L17J6=FILTER(D6#,H6#=13)
N6:P17N6=UNICHAR(J6#+9855)
R8R8=ROWS(J6#)
A10:A15A10=SEQUENCE(6,,9856)
B10:B15B10=UNICHAR(A10#)
Dynamic array formulas.
 
ExcelIsFun Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRS
1Task: Sample points of throwing 3 dice that togheter sum 13
23rd scenario - repetitions are allowed, order not important (type argument t=ca)
3=COMBINA(6,3)=ARRANGEMENTS(SEQUENCE(6),"ca",3)
456↓↓=BYROW(D6#,LAMBDA(x,SUM(x)))
5=ROWS(D6#)↓↓↓↓=FILTER(D6#,H6#=13)=UNICHAR(J6#+9855)
6561113166how many?
71124256=ROWS(J6#)
8=SEQUENCE(6,,9856)11353465
9↓↓=UNICHAR(A10#)1146355
1098561157445
1198571168
1298581225
1398591236
1498601247
1598611258
161269
171337
181348
191359
2013610
211449
2214510
2314611
2415511
2515612
2616613
272226
282237
292248
302259
3122610
322338
332349
3423510
3523611
3624410
3724511
3824612
3925512
4025613
4126614
423339
4333410
4433511
4533612
4634411
4734512
4834613
4935513
5035614
5136615
5244412
5344513
5444614
5545514
5645615
5746616
5855515
5955616
6056617
6166618
62
DICE 3
Cell Formulas
RangeFormula
A3,B9,R7,J5,N5,A5A3=FORMULATEXT(A4)
D3D3=FORMULATEXT(D6)
A4A4=COMBINA(6,3)
H4,A8H4=FORMULATEXT(H6)
A6A6=ROWS(D6#)
D6:F61D6=ARRANGEMENTS(SEQUENCE(6),"ca",3)
H6:H61H6=BYROW(D6#,LAMBDA(x,SUM(x)))
J6:L10J6=FILTER(D6#,H6#=13)
N6:P10N6=UNICHAR(J6#+9855)
R8R8=ROWS(J6#)
A10:A15A10=SEQUENCE(6,,9856)
B10:B15B10=UNICHAR(A10#)
Dynamic array formulas.
 
ExcelIsFun Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRS
1Task: Sample points of throwing 3 dice that togheter sum 13
24th scenario - no repetitions, order not important (type argument t=c)
3=COMBIN(6,3)=ARRANGEMENTS(SEQUENCE(6),"c",3)
420↓↓=BYROW(D6#,LAMBDA(x,SUM(x)))
5=ROWS(D6#)↓↓↓↓=FILTER(D6#,H6#=13)=UNICHAR(J6#+9855)
6201236256how many?
71247346=ROWS(J6#)
8=SEQUENCE(6,,9856)12582
9↓↓=UNICHAR(A10#)1269
1098561348
1198571359
12985813610
13985914510
14986014611
15986115612
162349
1723510
1823611
1924511
2024612
2125613
2234512
2334613
2435614
2545615
26
DICE 4
Cell Formulas
RangeFormula
A3,B9,R7,J5,N5,A5A3=FORMULATEXT(A4)
D3D3=FORMULATEXT(D6)
A4A4=COMBIN(6,3)
H4,A8H4=FORMULATEXT(H6)
A6A6=ROWS(D6#)
D6:F25D6=ARRANGEMENTS(SEQUENCE(6),"c",3)
H6:H25H6=BYROW(D6#,LAMBDA(x,SUM(x)))
J6:L7J6=FILTER(D6#,H6#=13)
N6:P7N6=UNICHAR(J6#+9855)
R8R8=ROWS(J6#)
A10:A15A10=SEQUENCE(6,,9856)
B10:B15B10=UNICHAR(A10#)
Dynamic array formulas.
 
An interesting challenge came to my attention: Choose cells that come closest to adding up to a certain total
Arrangements solution.xlsx
ABCDEFGHIJKLMNOP
1Task: Find cells of "Charge" clm that summed will get as close as possible to clm "A" total, respectively clm "B" totals.
2Nr.ChargeAD
31200.8866.96133.92Estimating numbers of cells needed to be summed to get to the min value out of the 2 totals (1425.1)
42275.8491.95183.89
53255.673.03182.57Average "Charge"How many average values to get to smallest amount 1425.1
64267.1198.41168.7=AVERAGE(B3:B18)=C19/F7
75187.0658.46128.6258.44755.514079 => 5 or 6
86250.0492.12157.92
97319.09124.86194.23Short preamble about excel limitations and their reflection to the performance of ARRANGEMENTS
108325.41113.89211.52Memory resources allocated that Excel formulas have access to, even in background calculations,
119224.4642.09182.37are quite limited when comes to combinatorics calculations minimal requirements.
1210226.571.53154.97rows limitation 1048576
1311281.71114.77166.94Examples
1412256.2976.89179.4=MIN(SEQUENCE(1048576))=MIN(SEQUENCE(,1048576))
1513222.9478.68144.2611
1614260.39140.21120.181048576+1 rows
1715353.41117.8235.61=MIN(SEQUENCE(1048577))=MIN(SEQUENCE(1048577))
1816228.4363.45164.98#VALUE!#VALUE!
19Sum4135.161425.12710.06
20Or if we call =sequence(1000000,53) works, but =sequence(1000000,54) returns: "Excel run out of resources…" message
21
22ARRANGEMENTS function is designed first to calculate permutations w repetitions pattern and refining this result
23can get us successively to permutations w/o repetitions, combinations w repetitions or combinations w/o repetitions.
24
25So, in our case we need to check if combin(16,5) and combin(16,6) will work.
26For that we have to check if permutationa(16,5) and permutationa(16,6) will exceed excel resources or not
27
28=PERMUTATIONA(16,5)
291048576 => this will work, value <=1048576
30rows=PERMUTATIONA(E31:E37,6)=F31#<=1048576
311616777216FALSE
321511390625FALSE
33147529536FALSE
34134826809FALSE
35122985984FALSE
36111771561FALSE
37101000000TRUE => for grouping 6 cells the array can have max 10 rows
38
SUM 1
Cell Formulas
RangeFormula
A3:A18A3=SEQUENCE(ROWS(B3:B18))
F6,F30,I30,F28,F17,I17,F14,I14,H6F6=FORMULATEXT(F7)
F7F7=AVERAGE(B3:B18)
H7H7=C19/F7
F15F15=MIN(SEQUENCE(1048576))
I15I15=MIN(SEQUENCE(,1048576))
F18,I18F18=MIN(SEQUENCE(1048577))
B19:D19B19=SUM(B3:B18)
F29F29=PERMUTATIONA(16,5)
F31:F37F31=PERMUTATIONA(E31:E37,6)
I31:I37I31=F31#<=1048576
Dynamic array formulas.
 
Arrangements solution.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAA
11. Grouping 5 cells. Concept. Step by step
2ChargeADIndex pattern calculationSum by row
3200.8866.96133.92=ARRANGEMENTS(SEQUENCE(16),"c",5)=BYROW(L6#,LAMBDA(x,SUM(x)))
4275.8491.95183.89↓↓Array grouping 5 cells all combinations↓↓Abs diffrenceExtracting smallest 12 values
5255.673.03182.57↓↓=ARRANGEMENTS(B3:B18,"c",5)↓↓=ABS(C19-R6#)=SMALL(T6#,SEQUENCE(12))
6267.1198.41168.712345200.88275.84255.6267.11187.061186.49238.610.06
7187.0658.46128.612346200.88275.84255.6267.11250.041249.47175.630.11
8250.0492.12157.9212347200.88275.84255.6267.11319.091318.52106.580.19
9319.09124.86194.2312348200.88275.84255.6267.11325.411324.84100.260.22
10325.41113.89211.5212349200.88275.84255.6267.11224.461223.89201.210.63
11224.4642.09182.37123410200.88275.84255.6267.11226.51225.93199.170.64
12226.571.53154.97123411200.88275.84255.6267.11281.711281.14143.960.7
13281.71114.77166.94123412200.88275.84255.6267.11256.291255.72169.380.77
14256.2976.89179.4123413200.88275.84255.6267.11222.941222.37202.730.88
15222.9478.68144.26123414200.88275.84255.6267.11260.391259.82165.280.89
16260.39140.21120.18123415200.88275.84255.6267.11353.411352.8472.261.17
17353.41117.8235.61123416200.88275.84255.6267.11228.431227.86197.241.4
18228.4363.45164.9812356200.88275.84255.6187.06250.041169.42255.68
194135.161425.12710.0612357200.88275.84255.6187.06319.091238.47186.63Index distribution corresponding to these values
2012358200.88275.84255.6187.06325.411244.79180.31=INDEX(F6#,XMATCH(V6#,T6#),SEQUENCE(,5))
21rows calculation check12359200.88275.84255.6187.06224.461143.84281.2648121315
22=COMBIN(16,5)123510200.88275.84255.6187.06226.51145.88279.222781113
234368123511200.88275.84255.6187.06281.711201.09224.011781015
24=ROWS(F6#)123512200.88275.84255.6187.06256.291175.67249.432671015
254368123513200.88275.84255.6187.06222.941142.32282.783481315
26123514200.88275.84255.6187.06260.391179.77245.334791415
27123515200.88275.84255.6187.06353.411272.79152.314681516
28123516200.88275.84255.6187.06228.431147.81277.2947121516
2912367200.88275.84255.6250.04319.091301.45123.6523678
3012368200.88275.84255.6250.04325.411307.77117.33348915
3112369200.88275.84255.6250.04224.461206.82218.28812141516
32123610200.88275.84255.6250.04226.51208.86216.2447101415
33123611200.88275.84255.6250.04281.711264.07161.03
34123612200.88275.84255.6250.04256.291238.65186.45checking results
35123613200.88275.84255.6250.04222.941205.3219.8=BYROW(INDEX(B3:B18,V21#),LAMBDA(x,SUM(x)))-C19
36123614200.88275.84255.6250.04260.391242.75182.350.06
37123615200.88275.84255.6250.04353.411335.7789.33-0.11
38123616200.88275.84255.6250.04228.431210.79214.310.19
3912378200.88275.84255.6319.09325.411376.8248.28-0.22
4012379200.88275.84255.6319.09224.461275.87149.23-0.63
41123710200.88275.84255.6319.09226.51277.91147.19-0.64
42123711200.88275.84255.6319.09281.711333.1291.98-0.7
43123712200.88275.84255.6319.09256.291307.7117.4-0.77
44123713200.88275.84255.6319.09222.941274.35150.750.88
45123714200.88275.84255.6319.09260.391311.8113.30.89
46123715200.88275.84255.6319.09353.411404.8220.28-1.17
47123716200.88275.84255.6319.09228.431279.84145.261.4
484368 rows12389200.88275.84255.6325.41224.461282.19142.91
49↓↓↓↓↓↓↓123810200.88275.84255.6325.41226.51284.23140.87
SUM 2
Cell Formulas
RangeFormula
F3,R3F3=FORMULATEXT(F6)
L5,V35,B24,B22,V20,T5,V5L5=FORMULATEXT(L6)
F6:J4373F6=ARRANGEMENTS(SEQUENCE(16),"c",5)
L6:P4373L6=ARRANGEMENTS(B3:B18,"c",5)
R6:R4373R6=BYROW(L6#,LAMBDA(x,SUM(x)))
T6:T4373T6=ABS(C19-R6#)
V6:V17V6=SMALL(T6#,SEQUENCE(12))
B19:D19B19=SUM(B3:B18)
V21:Z32V21=INDEX(F6#,XMATCH(V6#,T6#),SEQUENCE(,5))
B23B23=COMBIN(16,5)
B25B25=ROWS(F6#)
V36:V47V36=BYROW(INDEX(B3:B18,V21#),LAMBDA(x,SUM(x)))-C19
Dynamic array formulas.
 
The function GPRSUM, Grouping Sums, calls ARRANGEMENTS (functions set this thread post #24)
GPRSUM (ar,sm,nc,[fn])
ar: array
sm: reference value to be compared
nc: number chosen, group size
[fn]: first n values that return the smallest differences to reference value in ascending order, first is best, if omitted only first value is returned
Returns as first column the difference to the reference value followed by nc columns with the indexes distribution of the initial array ar
Excel Formula:
=LAMBDA(ar, sm, nc, [fn],
    LET(
        i, ARRANGEMENTS(SEQUENCE(ROWS(ar)), "c", nc),
        a, INDEX(ar, i, ),
        s, BYROW(a, LAMBDA(x, SUM(x))),
        d, ABS(sm - s),
        m, SMALL(d, SEQUENCE(MAX(fn, 1))),
        x, XMATCH(m, d),
        b, INDEX(i, x, SEQUENCE(, nc)),
        HSTACK(m, b)
    )
)
Arrangements solution.xlsx
ABCDEFGHIJKLM
1The function GRPSUM
2Nr.ChargeAD
31200.8866.96133.92fn argument omitted, => best result
42275.8491.95183.89difindex distribution
53255.673.03182.570.0648121315
64267.1198.41168.7=GRPSUM(B3:B18,C19,5)
75187.0658.46128.6
86250.0492.12157.92listing 12 smallest dif's, ascending order, fn=12
97319.09124.86194.23=GRPSUM(B3:B18,C19,5,12)
108325.41113.89211.520.0648121315
119224.4642.09182.370.112781113
1210226.571.53154.970.191781015
1311281.71114.77166.940.222671015
1412256.2976.89179.40.633481315
1513222.9478.68144.260.644791415
1614260.39140.21120.180.74681516
1715353.41117.8235.610.7747121516
1816228.4363.45164.980.8823678
19Sum4135.161425.12710.060.89348915
201.17812141516
211.447101415
22
23
24Fun fact: The author of the original post uploaded a picture (see attachment)
25of some results he managed to calculate manualy, also using 5 grouping
26These are:
27
28Nr.Charge
291200.88A1423.93=SUM(G36,G40,G42:G44)
302275.84D2711.23=SUM(G29:G35,G37:G39,G41)
313255.6
324267.11dif
335187.06=C19-J29
346250.041.17
357319.09
368325.41In our ranking this correspond to the 11th best.
379224.46Conclusion:
3810226.5Using the function we were able to find other
3911281.7110 distributions better than the "manual" one
4012256.29
4113222.94
4214260.39
4315353.41
4416228.43
45
SUM 3
Cell Formulas
RangeFormula
A3:A18,F29:F44A3=SEQUENCE(ROWS(B3:B18))
F5:K5F5=GRPSUM(B3:B18,C19,5)
F6F6=FORMULATEXT(F5)
F9,J33F9=FORMULATEXT(F10)
F10:K21F10=GRPSUM(B3:B18,C19,5,12)
B19:D19B19=SUM(B3:B18)
J29J29=SUM(G36,G40,G42:G44)
K29:K30K29=FORMULATEXT(J29)
J30J30=SUM(G29:G35,G37:G39,G41)
J34J34=C19-J29
Dynamic array formulas.
grp sum.png
 
Arrangements solution.xlsx
ABCDEFGHIJKLMNOPQR
12. Grouping 6 cells => max array has to have 10 rows
2Nr.ChargeAD
31200.8866.96133.92Choosing 10 elements out of total 16 can be another combination problem on itself.
42275.8491.95183.89=COMBIN(16,10)
53255.673.03182.57There are8008ways to arrange 10 elements to cover all posibilities
64267.1198.41168.7
75187.0658.46128.6At least what we can do is to try iterativley 16-10+1=7 "consecutive" arrays top to bottom,
86250.0492.12157.92and see what diffrences will get:
97319.09124.86194.23=GRPSUM(B3:B12,C19,6,5)
108325.41113.89211.52first 10 B3:B120.001457910
119224.4642.09182.37fn=50.511346910
1210226.571.53154.975.191358910
1311281.71114.77166.945.62356910
1412256.2976.89179.45.912456910
1513222.9478.68144.26
1614260.39140.21120.18We were lucky, we have found the perfect grouping, dif=0
1715353.41117.8235.61=GRPSUM(B4:B13,C19,6,5)
1816228.4363.45164.98scnd 10 B4:B130.272458910
19Sum4135.161425.12710.06fn=55.6124589
205.91134589
2111.47123489
2211.783458910
23
24Note: Index values apply to B4:B13 array => relative index numbers
25
26
27array nrdifindexes (absolute)
2810.001457910
2920.2735691011
3030.2735691011
3140.565610111213
3250.565610111213
33615.526910121314
3476.0991012131416
35
36range H28:H34=LET(x,GRPSUM(INDEX($B$3:$B$18,SEQUENCE(10,,G28)),$C$19,6),IF(SEQUENCE(,7)>1,x+G28-1,x))
37
SUM 4
Cell Formulas
RangeFormula
A3:A18A3=SEQUENCE(ROWS(B3:B18))
G4,H17,H9G4=FORMULATEXT(G5)
G5G5=COMBIN(16,10)
H10:N14H10=GRPSUM(B3:B12,C19,6,5)
H18:N22H18=GRPSUM(B4:B13,C19,6,5)
B19:D19B19=SUM(B3:B18)
H28:N34H28=LET(x,GRPSUM(INDEX($B$3:$B$18,SEQUENCE(10,,G28)),$C$19,6),IF(SEQUENCE(,7)>1,x+G28-1,x))
G36G36=FORMULATEXT(H28)
Dynamic array formulas.
 
Humble conclusion:
Approaching this challenge using combinatorics is a fair straight solution. Because of its limitations in general, the performance is quite low, but is far better than nothing.
Actually, any combinatorics approach of any task can run out of resources quite fast. With better resources it could be feasible.
For larger arrays, algorithms can be designed to work with arrangements, using partial sections and partial values.
Probably other solutions should be considered, like using statistical tools.
Or using random engines for random selections. It's fun.
Arrangements solution.xlsx
ABCDEFGHIJKLMNOPQ
1To take advantage of the function, we can also try random selection until we get satisfactory results.
2Nr.ChargeADRandom selection 10 elements, 6 cells grouping
31200.8866.96133.92random 10 indexes
42275.8491.95183.89=INDEX(D26#,SEQUENCE(10))
53255.673.03182.57↓↓↓indexes valuesHit F9 until dif is small enough
64267.1198.41168.7↓↓↓=INDEX(B3:B18,F7#)
75187.0658.46128.65187.060.183456810
86250.0492.12157.9214260.39
97319.09124.86194.2310226.5Values extraction
108325.41113.89211.529224.46=INDEX(H7#,K7:P7)
119224.4642.09182.3712256.29226.5224.46256.29200.88250.04267.11
1210226.571.53154.971200.88
1311281.71114.77166.9416228.43
1412256.2976.89179.46250.04
1513222.9478.68144.2615353.41
1614260.39140.21120.184267.11
1715353.41117.8235.61
1816228.4363.45164.98
19Sum4135.161425.12710.06
20
21
22Random selection engine indexes
23=SEQUENCE(16)
24↓↓↓=RANDARRAY(16)
25↓↓↓↓↓↓=SORTBY(B26#,C26#)
2610.41515
2720.949614
2830.961910
2940.82759
3050.023912
3160.64361
3270.942316
3380.90516
3490.318615
35100.11334
36110.879211
37120.36748
38130.99357
39140.06922
40150.75183
41160.609213
42
SUM 5
Cell Formulas
RangeFormula
F4,B23F4=FORMULATEXT(F7)
H6,D25,K10H6=FORMULATEXT(H7)
F7:F16F7=INDEX(D26#,SEQUENCE(10))
H7:H16H7=INDEX(B3:B18,F7#)
J7:P7J7=GRPSUM(H7#,C19,6)
K11:P11K11=INDEX(H7#,K7:P7)
C24C24=FORMULATEXT(C26)
B26:B41B26=SEQUENCE(16)
C26:C41C26=RANDARRAY(16)
D26:D41D26=SORTBY(B26#,C26#)
Dynamic array formulas.
 
Really wonderful function!
I couldn't get this to work for an array {1, 2, 3, 4, 5, 6, 7}, for "c", with the nc = 7.
It freezes my Excel.
Maybe it's just me?
Or its trying to do too many recursions, on both T_CA and T_P?
 

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top