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
T_CAF(a) Tool function calculating Combinations indexes, ( COMBINA ) using other Function AFUSBYROW.
Excel Formula:
=LAMBDA(a,UNIQUE(AFUSBYROW(a,,,1)))
LAMBDA 1.2.1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1T_CAF(a) , alternative of T_CA(a) or T_CAN(a), using other Functions (AFUSBYROW) - filters only rows in ascending order, order is not important
2( f,u,s are the filter, unique, sort, arguments of AFUSBYROW )
3
41. combinations with repetitions2. combinations w/o repetitionsother functions
5permutationa(4,3)step 1 sort ascending by each row of aAFUSBYROW
6n,4,c,3f,u,omitted,s,1step 2 unique(a')step 3 single cell
7=T_PA(4,3)a=AFUSBYROW(A8#,,,1)=UNIQUE(E8#)=T_CAF(A8#)=T_PF(T_PA(4,3))=T_CAF(Q8#)
8111111a'111111123123
9112112112112124124
10113113113113132134
11114114114114134234
12121112122122142
13122122123123143
14123123124124213=T_PF(T_CAF(A8#))
15124124133133214123
16131113134134231124
17132123144144234134
18133133222222241234
19134134223223243
20141114224224312
21142124233233314
22143134234234321
23144144244244324
24211112333333341
25212122334334342
26213123344344412
27214124444444413
28221122421
29222222423
30223223431
31224224432
32231123
33232223
34233233
35234234
36241124
37242224
38243234
39244244
40311113
41312123
42313133
43314134
44321123
45322223
46323233
47324234
48331133
49332233
50333333
51334334
52341134
53342234
54343334
55344344
56411114
57412124
58413134
59414144
60421124
61422224
62423234
63424244
64431134
65432234
66433334
67434344
68441144
69442244
70443344
71444444
72
ARRG np7
Cell Formulas
RangeFormula
A7,U14,Q7,U7,E7,I7,M7A7=FORMULATEXT(A8)
A8:C71A8=T_PA(4,3)
E8:G71E8=AFUSBYROW(A8#,,,1)
I8:K27I8=UNIQUE(E8#)
M8:O27M8=T_CAF(A8#)
Q8:S31Q8=T_PF(T_PA(4,3))
U8:W11U8=T_CAF(Q8#)
U15:W18U15=T_PF(T_CAF(A8#))
Dynamic array formulas.
 
LAMBDA 1.2.1.xlsx
ABCDEFGHIJKLMNOPQRSTUVWX
1Task: filtering only rows of an array that are in ascending order, general use, all 3 methods T_CA(a) , T_CAN(a) , T_CAF(a)
2
3recursivelambda helperother functions
4samplea=T_CA(A5:E12)=T_CAN(A5:E12)=T_CAF(A5:E12)
5abcdeabcdeabcdeabcde
6acbde123451234512345
712345aabcdaabcdaabcd
813245122341223412234
9aabcd123ab123ab123ab
1012234
11ab123
12123ab
13
14a without rows with dups
15=T_P(A5:E12)=T_CA(A16#)=T_CAN(A16#)=T_CAF(A16#)
16abcdeabcdeabcdeabcde
17acbde123451234512345
1812345123ab123ab123ab
1913245
20ab123
21123abfrom a directly
22
23=T_CA(T_P(A5:E12))=T_CAN(T_P(A5:E12))=T_CAF(T_PF(A5:E12))
24abcdeabcdeabcde
25123451234512345
26123ab123ab123ab
27
28=T_P(T_CA(A5:E12))=T_PN(T_CAN(A5:E12))=T_PF(T_CAF(A5:E12))
29abcdeabcdeabcde
30123451234512345
31123ab123ab123ab
32
ARRG np8
Cell Formulas
RangeFormula
G4,S28,M28,G28,S23,M23,G23,S15,M15,G15,A15,S4,M4G4=FORMULATEXT(G5)
G5:K9G5=T_CA(A5:E12)
M5:Q9M5=T_CAN(A5:E12)
S5:W9S5=T_CAF(A5:E12)
A16:E21A16=T_P(A5:E12)
G16:K18G16=T_CA(A16#)
M16:Q18M16=T_CAN(A16#)
S16:W18S16=T_CAF(A16#)
G24:K26G24=T_CA(T_P(A5:E12))
M24:Q26M24=T_CAN(T_P(A5:E12))
S24:W26S24=T_CAF(T_PF(A5:E12))
G29:K31G29=T_P(T_CA(A5:E12))
M29:Q31M29=T_PN(T_CAN(A5:E12))
S29:W31S29=T_PF(T_CAF(A5:E12))
Dynamic array formulas.
 
Regarding component functions, the only stone left unturned is T_PA(n,c), a simple and straight forward function using MOD.
LAMBDA 1.2.1.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1T_PA(n,c) step by step.
2 =LAMBDA(n,c,MOD(ROUNDUP(SEQUENCE(n^c)/n^(c-SEQUENCE(,c)),0)-1,n)+1)
3n=4,c=3check
4=SEQUENCE(4^3)=SEQUENCE(,3)=SEQUENCE(4^3)/4^(3-SEQUENCE(,3))=ROUNDUP(H5#,0)=MOD(L5#-1,4)+1=T_PA(4,3)
511230.06250.251111111111
620.1250.52112112112
73=3-SEQUENCE(,3)0.18750.753113113113
842100.2514114114114
950.31251.255125121121
106=4^(3-SEQUENCE(,3))0.3751.56126122122
11716410.43751.757127123123
1280.528128124124
1390.56252.259139131131
14100.6252.5101310132132
15110.68752.75111311133133
16120.753121312134134
17130.81253.25131413141141
18140.8753.5141414142142
19150.93753.75151415143143
201614161416144144
21171.06254.25172517211211
22181.1254.5182518212212
23191.18754.75192519213213
24201.255202520214214
25211.31255.25212621221221
26221.3755.5222622222222
27231.43755.75232623223223
28241.56242624224224
29251.56256.25252725231231
30261.6256.5262726232232
31271.68756.75272727233233
32281.757282728234234
33291.81257.25292829241241
34301.8757.5302830242242
35311.93757.75312831243243
363228322832244244
37332.06258.25333933311311
38342.1258.5343934312312
39352.18758.75353935313313
40362.259363936314314
41372.31259.253731037321321
42382.3759.53831038322322
43392.43759.753931039323323
44402.5104031040324324
45412.562510.254131141331331
46422.62510.54231142332332
47432.687510.754331143333333
48442.75114431144334334
49452.812511.254531245341341
50462.87511.54631246342342
51472.937511.754731247343343
52483124831248344344
53493.062512.254941349411411
54503.12512.55041350412412
55513.187512.755141351413413
56523.25135241352414414
57533.312513.255341453421421
58543.37513.55441454422422
59553.437513.755541455423423
60563.5145641456424424
61573.562514.255741557431431
62583.62514.55841558432432
63593.687514.755941559433433
64603.75156041560434434
65613.812515.256141661441441
66623.87515.56241662442442
67633.937515.756341663443443
68644166441664444444
69
ARRG np9
Cell Formulas
RangeFormula
B4,D4,H4,L4,P4,T4,D10,D7B4=FORMULATEXT(B5)
B5:B68B5=SEQUENCE(4^3)
D5:F5D5=SEQUENCE(,3)
H5:J68H5=SEQUENCE(4^3)/4^(3-SEQUENCE(,3))
L5:N68L5=ROUNDUP(H5#,0)
P5:R68P5=MOD(L5#-1,4)+1
T5:V68T5=T_PA(4,3)
D8:F8D8=3-SEQUENCE(,3)
D11:F11D11=4^(3-SEQUENCE(,3))
Dynamic array formulas.
 
We have seen 3 design variants for tool lambdas, using recursion, lambda helper functions, and other custom-made function.
Chose as final variant the set of tool lambdas that use lambda helper functions.
T_PA(n,c)
Excel Formula:
=LAMBDA(n, c, MOD(ROUNDUP(SEQUENCE(n ^ c) / n ^ (c - SEQUENCE(, c)), 0) - 1, n) + 1)

T_P(a)
Excel Formula:
=LAMBDA(a,
    LET(c, COLUMNS(a),
        FILTER(a,BYROW(REDUCE(0, SEQUENCE(c), LAMBDA(v,i, v + (INDEX(a, , i) = a))),LAMBDA(x, SUM(x) = c)))
    )
)

T_CA(a)
Excel Formula:
=LAMBDA(a,
    LET(c, COLUMNS(a),
        FILTER(a,REDUCE(1,SEQUENCE(c - 1),LAMBDA(v,i, v * (INDEX(a, , i) <= INDEX(a, , i + 1)))))
    )
)

ARRANGEMENTS(a,t,c) Note: Only modification to the initial one, replaced AFLAT(a) with TOCOL(IF(a = "", NA(), a), 3)
Excel Formula:
=LAMBDA(a,t,c,
    IF(AND(t <> {"p","pa","c","ca"}),"check type",
        LET(k, MAX(1, c),x, TOCOL(IF(a = "", NA(), a), 3),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)))))
        )
    )
)
 
Example inspired from today's (8May22) ExcelIsFun YT Excel Statistical Analysis 36: Sampling & Sampling Distribution of Sample Means (Xbar)
Create the following table using ARRANGEMENTS (min 15:48)
Ch07-ESA.xlsm
ABCDEFGHIJKL
1Pop Size = N =7
2Sample Size = n =3
3Number of Samples Possible:35
4
5Sales RepSalesSales Rep 1Sales Rep 2Sales Rep 3Sales 1Sales 2Sales 3XbarP(Sample)
6Jo185JoSiouxChin1852502102150.028571429
7Sioux250JoSiouxSheliadawn185250310248.33333330.028571429
8Chin210JoSiouxGigi185250298244.33333330.028571429
9Sheliadawn310JoSiouxTyrone1852504022790.028571429
10Gigi298JoSiouxKip185250370268.33333330.028571429
11Tyrone402JoChinSheliadawn1852103102350.028571429
12Kip370JoChinGigi1852102982310.028571429
13JoChinTyrone185210402265.66666670.028571429
14JoChinKip1852103702550.028571429
15JoSheliadawnGigi185310298264.33333330.028571429
16JoSheliadawnTyrone1853104022990.028571429
17JoSheliadawnKip185310370288.33333330.028571429
18JoGigiTyrone1852984022950.028571429
19JoGigiKip185298370284.33333330.028571429
20JoTyroneKip1854023703190.028571429
21SiouxChinSheliadawn250210310256.66666670.028571429
22SiouxChinGigi250210298252.66666670.028571429
23SiouxChinTyrone250210402287.33333330.028571429
24SiouxChinKip250210370276.66666670.028571429
25SiouxSheliadawnGigi2503102982860.028571429
26SiouxSheliadawnTyrone250310402320.66666670.028571429
27SiouxSheliadawnKip2503103703100.028571429
28SiouxGigiTyrone250298402316.66666670.028571429
29SiouxGigiKip2502983703060.028571429
30SiouxTyroneKip250402370340.66666670.028571429
31ChinSheliadawnGigi210310298272.66666670.028571429
32ChinSheliadawnTyrone210310402307.33333330.028571429
33ChinSheliadawnKip210310370296.66666670.028571429
34ChinGigiTyrone210298402303.33333330.028571429
35ChinGigiKip210298370292.66666670.028571429
36ChinTyroneKip210402370327.33333330.028571429
37SheliadawnGigiTyrone310298402336.66666670.028571429
38SheliadawnGigiKip3102983703260.028571429
39SheliadawnTyroneKip310402370360.66666670.028571429
40GigiTyroneKip298402370356.66666670.028571429
41
All Possible Samples (an)
Cell Formulas
RangeFormula
E1E1=COUNTA(A6:A12)
E3E3=COMBIN(E1,E2)
G6:I40G6=XLOOKUP(D6:F40,A6:A12,B6:B12)
J6:J40J6=AVERAGE(G6:I6)
K6:K40K6=1/$E$3
Dynamic array formulas.
 
Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQ
1Pop Size = N =7
2Sample Size = n =3
3Number of Samples Possible:35=MAP(D6#,LAMBDA(x,VLOOKUP(x,A6:B12,2,0)))
4↓↓=BYROW(H6#,LAMBDA(x,AVERAGE(x)))
5Sales RepSales=ARRANGEMENTS(A6:A12,"c",E2)↓↓↓↓=SEQUENCE(ROWS(D6#))^0/ROWS(D6#)
6Jo185JoSiouxChin1852502102150.028571429
7Sioux250JoSiouxSheliadawn185250310248.33333330.028571429
8Chin210JoSiouxGigi185250298244.33333330.028571429
9Sheliadawn310JoSiouxTyrone1852504022790.028571429
10Gigi298JoSiouxKip185250370268.33333330.028571429
11Tyrone402JoChinSheliadawn1852103102350.028571429
12Kip370JoChinGigi1852102982310.028571429
13JoChinTyrone185210402265.66666670.028571429
14JoChinKip1852103702550.028571429
15JoSheliadawnGigi185310298264.33333330.028571429
16JoSheliadawnTyrone1853104022990.028571429
17JoSheliadawnKip185310370288.33333330.028571429
18JoGigiTyrone1852984022950.028571429
19JoGigiKip185298370284.33333330.028571429
20JoTyroneKip1854023703190.028571429
21SiouxChinSheliadawn250210310256.66666670.028571429
22SiouxChinGigi250210298252.66666670.028571429
23SiouxChinTyrone250210402287.33333330.028571429
24SiouxChinKip250210370276.66666670.028571429
25SiouxSheliadawnGigi2503102982860.028571429
26SiouxSheliadawnTyrone250310402320.66666670.028571429
27SiouxSheliadawnKip2503103703100.028571429
28SiouxGigiTyrone250298402316.66666670.028571429
29SiouxGigiKip2502983703060.028571429
30SiouxTyroneKip250402370340.66666670.028571429
31ChinSheliadawnGigi210310298272.66666670.028571429
32ChinSheliadawnTyrone210310402307.33333330.028571429
33ChinSheliadawnKip210310370296.66666670.028571429
34ChinGigiTyrone210298402303.33333330.028571429
35ChinGigiKip210298370292.66666670.028571429
36ChinTyroneKip210402370327.33333330.028571429
37SheliadawnGigiTyrone310298402336.66666670.028571429
38SheliadawnGigiKip3102983703260.028571429
39SheliadawnTyroneKip310402370360.66666670.028571429
40GigiTyroneKip298402370356.66666670.028571429
41
Sheet1
Cell Formulas
RangeFormula
E1E1=COUNTA(A6:A12)
E3E3=COMBIN(E1,E2)
H3H3=FORMULATEXT(H6)
L4L4=FORMULATEXT(L6)
D5,N5D5=FORMULATEXT(D6)
D6:F40D6=ARRANGEMENTS(A6:A12,"c",E2)
H6:J40H6=MAP(D6#,LAMBDA(x,VLOOKUP(x,A6:B12,2,0)))
L6:L40L6=BYROW(H6#,LAMBDA(x,AVERAGE(x)))
N6:N40N6=SEQUENCE(ROWS(D6#))^0/ROWS(D6#)
Dynamic array formulas.
 
Single cell formula in D6:
Excel Formula:
=LET(rp,A8:A14,sl,B8:B14,n,E2,
         a,ARRANGEMENTS(rp,"c",n),r,ROWS(a),
         b,MAP(a,LAMBDA(x,XLOOKUP(x,rp,sl))),
         c,BYROW(b,LAMBDA(x,AVERAGE(x))),
         d,SEQUENCE(r)^0/r,
         HSTACK(a,b,c,d)
 )
Ch07-ESA.xlsm
ABCDEFGHIJKL
1Pop Size = N =7
2Sample Size = n =3
3Number of Samples Possible:35
4
5Sales RepSalesSales Rep 1Sales Rep 2Sales Rep 3Sales 1Sales 2Sales 3XbarP(Sample)
6Jo185JoSiouxChin1852502102150.028571429
7Sioux250JoSiouxSheliadawn185250310248.33333330.028571429
8Chin210JoSiouxGigi185250298244.33333330.028571429
9Sheliadawn310JoSiouxTyrone1852504022790.028571429
10Gigi298JoSiouxKip185250370268.33333330.028571429
11Tyrone402JoChinSheliadawn1852103102350.028571429
12Kip370JoChinGigi1852102982310.028571429
13JoChinTyrone185210402265.66666670.028571429
14JoChinKip1852103702550.028571429
15JoSheliadawnGigi185310298264.33333330.028571429
16JoSheliadawnTyrone1853104022990.028571429
17JoSheliadawnKip185310370288.33333330.028571429
18JoGigiTyrone1852984022950.028571429
19JoGigiKip185298370284.33333330.028571429
20JoTyroneKip1854023703190.028571429
21SiouxChinSheliadawn250210310256.66666670.028571429
22SiouxChinGigi250210298252.66666670.028571429
23SiouxChinTyrone250210402287.33333330.028571429
24SiouxChinKip250210370276.66666670.028571429
25SiouxSheliadawnGigi2503102982860.028571429
26SiouxSheliadawnTyrone250310402320.66666670.028571429
27SiouxSheliadawnKip2503103703100.028571429
28SiouxGigiTyrone250298402316.66666670.028571429
29SiouxGigiKip2502983703060.028571429
30SiouxTyroneKip250402370340.66666670.028571429
31ChinSheliadawnGigi210310298272.66666670.028571429
32ChinSheliadawnTyrone210310402307.33333330.028571429
33ChinSheliadawnKip210310370296.66666670.028571429
34ChinGigiTyrone210298402303.33333330.028571429
35ChinGigiKip210298370292.66666670.028571429
36ChinTyroneKip210402370327.33333330.028571429
37SheliadawnGigiTyrone310298402336.66666670.028571429
38SheliadawnGigiKip3102983703260.028571429
39SheliadawnTyroneKip310402370360.66666670.028571429
40GigiTyroneKip298402370356.66666670.028571429
41
All Possible Samples (an) (2)
Cell Formulas
RangeFormula
E1E1=COUNTA(A6:A12)
E3E3=COMBIN(E1,E2)
D6:K40D6=LET(rp,A6:A12,sl,B6:B12,n,E2,a,ARRANGEMENTS(rp,"c",n),r,ROWS(a),b,MAP(a,LAMBDA(x,XLOOKUP(x,rp,sl))),c,BYROW(b,LAMBDA(x,AVERAGE(x))),d,SEQUENCE(r)^0/r,HSTACK(a,b,c,d))
Dynamic array formulas.
 
For the ones familiar with probabilities, ARRANGEMENTS can also be useful to create so-called sample points.
A deck of cards has face cards "F"(A,J,Q,K) and no face cards "NF".
Task: List all possible distributions of 5 card extractions considering only the ones that contain 2 face "F" cards.
Will use permutations with repetitions,"pa", n=2 (F,NF) , nr. chosen c=5 with FILTER.
Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRST
1
2aFNF
3
4t,"pa",c,5=BYROW(B6#,LAMBDA(x,SUM(--(x="f"))=2))
5=ARRANGEMENTS(B2:C2,"pa",5)↓↓=FILTER(B6#,H6#)
6FFFFFFALSEFFNFNFNF
7FFFFNFFALSEFNFFNFNF
8FFFNFFFALSEFNFNFFNF
9FFFNFNFFALSEFNFNFNFF
10FFNFFFFALSENFFFNFNF
11FFNFFNFFALSENFFNFFNF
12FFNFNFFFALSENFFNFNFF
13FFNFNFNFTRUENFNFFFNF
14FNFFFFFALSENFNFFNFF
15FNFFFNFFALSENFNFNFFF
16FNFFNFFFALSE
17FNFFNFNFTRUEhow many?
18FNFNFFFFALSE=ROWS(J6#)
19FNFNFFNFTRUE10
20FNFNFNFFTRUE
21FNFNFNFNFFALSEBecause n<c (2<5) permutations or combinations w/o repetitions ("p" or "c") will not work
22NFFFFFFALSE
23NFFFFNFFALSE=ARRANGEMENTS(B2:C2,"p",5)
24NFFFNFFFALSEnr chosen>n !
25NFFFNFNFTRUE
26NFFNFFFFALSE=ARRANGEMENTS(B2:C2,"c",5)
27NFFNFFNFTRUEnr chosen>n !
28NFFNFNFFTRUE
29NFFNFNFNFFALSE
30NFNFFFFFALSE
31NFNFFFNFTRUE
32NFNFFNFFTRUE
33NFNFFNFNFFALSE
34NFNFNFFFTRUE
35NFNFNFFNFFALSE
36NFNFNFNFFFALSE
37NFNFNFNFNFFALSE
38
Sheet3
Cell Formulas
RangeFormula
H4H4=FORMULATEXT(H6)
B5,J26,J23,K18,J5B5=FORMULATEXT(B6)
B6:F37B6=ARRANGEMENTS(B2:C2,"pa",5)
H6:H37H6=BYROW(B6#,LAMBDA(x,SUM(--(x="f"))=2))
J6:N15J6=FILTER(B6#,H6#)
K19K19=ROWS(J6#)
J24J24=ARRANGEMENTS(B2:C2,"p",5)
J27J27=ARRANGEMENTS(B2:C2,"c",5)
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H6:H37Expression=H6textNO
B6:F37Expression=$H6textNO
 
For this example, face cards "F"=(J,Q,K), "A" the aces, and the rest no face cards "NF".
Task: List all possible distributions of 6 card extractions considering only the ones that contain 2 face cards "F" and 1 Ace card "A".
Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1
2aAFNF
3=BYROW(B5#,LAMBDA(x,AND(SUM(--(x="a"))=1,SUM(--(x="f"))=2)))
4=ARRANGEMENTS(B2:D2,"pa",6)↓↓=FILTER(B5#,I5#)
5AAAAAAFALSEchecking AFFNFNFNFhow many ?
6AAAAAFFALSE=PERMUTATIONA(3,6)AFNFFNFNF=ROWS(P5#)
7AAAAANFFALSE729AFNFNFFNF60
8AAAAFAFALSEAFNFNFNFF
9AAAAFFFALSE=ROWS(B5#)ANFFFNFNF
10AAAAFNFFALSE729ANFFNFFNF
11AAAANFAFALSEANFFNFNFF
12AAAANFFFALSEANFNFFFNF
13AAAANFNFFALSEANFNFFNFF
14AAAFAAFALSEANFNFNFFF
15AAAFAFFALSEFAFNFNFNF
16AAAFANFFALSEFANFFNFNF
17AAAFFAFALSEFANFNFFNF
18AAAFFFFALSEFANFNFNFF
19AAAFFNFFALSEFFANFNFNF
20AAAFNFAFALSEFFNFANFNF
21AAAFNFFFALSEFFNFNFANF
22AAAFNFNFFALSEFFNFNFNFA
23AAANFAAFALSEFNFAFNFNF
24AAANFAFFALSEFNFANFFNF
25AAANFANFFALSEFNFANFNFF
26AAANFFAFALSEFNFFANFNF
27AAANFFFFALSEFNFFNFANF
28AAANFFNFFALSEFNFFNFNFA
29AAANFNFAFALSEFNFNFAFNF
30AAANFNFFFALSEFNFNFANFF
31AAANFNFNFFALSEFNFNFFANF
32AAFAAAFALSEFNFNFFNFA
33AAFAAFFALSEFNFNFNFAF
34AAFAANFFALSEFNFNFNFFA
35AAFAFAFALSENFAFFNFNF
36AAFAFFFALSENFAFNFFNF
37AAFAFNFFALSENFAFNFNFF
38AAFANFAFALSENFANFFFNF
39AAFANFFFALSENFANFFNFF
40AAFANFNFFALSENFANFNFFF
41AAFFAAFALSENFFAFNFNF
42AAFFAFFALSENFFANFFNF
43AAFFANFFALSENFFANFNFF
44AAFFFAFALSENFFFANFNF
45AAFFFFFALSENFFFNFANF
46AAFFFNFFALSENFFFNFNFA
47AAFFNFAFALSENFFNFAFNF
48AAFFNFFFALSENFFNFANFF
49AAFFNFNFFALSENFFNFFANF
50AAFNFAAFALSENFFNFFNFA
51AAFNFAFFALSENFFNFNFAF
52AAFNFANFFALSENFFNFNFFA
53AAFNFFAFALSENFNFAFFNF
54AAFNFFFFALSENFNFAFNFF
55AAFNFFNFFALSENFNFANFFF
56AAFNFNFAFALSENFNFFAFNF
57AAFNFNFFFALSENFNFFANFF
58AAFNFNFNFFALSENFNFFFANF
59AANFAAAFALSENFNFFFNFA
60AANFAAFFALSENFNFFNFAF
61AANFAANFFALSENFNFFNFFA
62AANFAFAFALSENFNFNFAFF
63AANFAFFFALSENFNFNFFAF
64AANFAFNFFALSEdown to 729 rowsNFNFNFFFA
65AANFANFAFALSE↓↓↓↓↓↓↓↓↓↓
Sheet4
Cell Formulas
RangeFormula
I3I3=FORMULATEXT(I5)
B4,K9,W6,K6,P4B4=FORMULATEXT(B5)
B5:G733B5=ARRANGEMENTS(B2:D2,"pa",6)
I5:I733I5=BYROW(B5#,LAMBDA(x,AND(SUM(--(x="a"))=1,SUM(--(x="f"))=2)))
P5:U64P5=FILTER(B5#,I5#)
K7K7=PERMUTATIONA(3,6)
W7W7=ROWS(P5#)
K10K10=ROWS(B5#)
Dynamic array formulas.
 
Sample point distributions for the same task, all 4 scenarios.
Task: Sample point distributions of throwing 3 dice that together sum 13.
1st scenario - repetitions are allowed, order is important (type argument t=pa)
2nd scenario - no repetitions, order is important (type argument t=p)
3rd scenario - repetitions are allowed, order not important (type argument t=ca)
4th scenario - no repetitions, order not important (type argument t=c)
ExcelIsFun Ch07-ESA.xlsm
ABCDEFGHIJKLMNOPQRS
1Task: Sample points of throwing 3 dice that togheter sum 13
21st scenario - repetitions are allowed, order is important (type argument t=pa)
3=PERMUTATIONA(6,3)=ARRANGEMENTS(SEQUENCE(6),"pa",3)
4216↓↓=BYROW(D6#,LAMBDA(x,SUM(x)))
5=ROWS(D6#)↓↓↓↓=FILTER(D6#,H6#=13)=UNICHAR(J6#+9855)
62161113166how many?
71124256=ROWS(J6#)
8=SEQUENCE(6,,9856)113526521
9↓↓=UNICHAR(A10#)1146346
1098561157355
1198571168364
1298581214436
1398591225445
1498601236454
1598611247463
161258526
171269535
181315544
191326553
201337562
211348616
221359625
2313610634
241416643
251427652
261438661
271449
2814510
2914611
301517
311528
321539
3315410
3415511
3515612
361618
371629
3816310
3916411
4016512
4116613
422114
432125
442136
452147
462158
472169
482215
492226
502237
512248
522259
5322610
542316
552327
562338
572349
5823510
5923611
602417down to 216 rows
612428↓↓↓↓↓↓↓↓↓↓
622439
DICE 1
Cell Formulas
RangeFormula
A3,B9,R7,J5,N5,A5A3=FORMULATEXT(A4)
D3D3=FORMULATEXT(D6)
A4A4=PERMUTATIONA(6,3)
H4,A8H4=FORMULATEXT(H6)
A6A6=ROWS(D6#)
D6:F221D6=ARRANGEMENTS(SEQUENCE(6),"pa",3)
H6:H221H6=BYROW(D6#,LAMBDA(x,SUM(x)))
J6:L26J6=FILTER(D6#,H6#=13)
N6:P26N6=UNICHAR(J6#+9855)
R8R8=ROWS(J6#)
A10:A15A10=SEQUENCE(6,,9856)
B10:B15B10=UNICHAR(A10#)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,945
Messages
6,175,555
Members
452,652
Latest member
eduedu

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