lrobbo314
Well-known Member
- Joined
- Jul 14, 2008
- Messages
- 3,963
- Office Version
- 365
- Platform
- Windows
Using the dynamic array functions, I created a formula that will return permutations, with or without repetitions, based on a range of values you select. I used the lambda function to turn it into an easy-to-use formula.
Just wanted to share because I think it's cool, permutations come up a lot, and I'd like to see what everyone thinks. I'm sure that this formula could be optimized or shortened.
Name Manager Lambda function "PermutX"
Just wanted to share because I think it's cool, permutations come up a lot, and I'd like to see what everyone thinks. I'm sure that this formula could be optimized or shortened.
permutationx.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Values | Repitions | Results | |||||||
2 | Dog | 0 | Dog | Cat | Bird | Lizard | ||||
3 | Cat | Dog | Cat | Lizard | Bird | |||||
4 | Bird | Dog | Bird | Cat | Lizard | |||||
5 | Lizard | Dog | Bird | Lizard | Cat | |||||
6 | Dog | Lizard | Cat | Bird | ||||||
7 | Dog | Lizard | Bird | Cat | ||||||
8 | Cat | Dog | Bird | Lizard | ||||||
9 | Cat | Dog | Lizard | Bird | ||||||
10 | Cat | Bird | Dog | Lizard | ||||||
11 | Cat | Bird | Lizard | Dog | ||||||
12 | Cat | Lizard | Dog | Bird | ||||||
13 | Cat | Lizard | Bird | Dog | ||||||
14 | Bird | Dog | Cat | Lizard | ||||||
15 | Bird | Dog | Lizard | Cat | ||||||
16 | Bird | Cat | Dog | Lizard | ||||||
17 | Bird | Cat | Lizard | Dog | ||||||
18 | Bird | Lizard | Dog | Cat | ||||||
19 | Bird | Lizard | Cat | Dog | ||||||
20 | Lizard | Dog | Cat | Bird | ||||||
21 | Lizard | Dog | Bird | Cat | ||||||
22 | Lizard | Cat | Dog | Bird | ||||||
23 | Lizard | Cat | Bird | Dog | ||||||
24 | Lizard | Bird | Dog | Cat | ||||||
25 | Lizard | Bird | Cat | Dog | ||||||
Sheet3 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
E2:H25 | E2 | =PermutX(A2:A5,C2) |
Dynamic array formulas. |
permutationx.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | Values | Repitions | Results | ||||||
2 | Dog | 1 | Dog | Dog | Dog | ||||
3 | Cat | Dog | Dog | Cat | |||||
4 | Bird | Dog | Dog | Bird | |||||
5 | Dog | Cat | Dog | ||||||
6 | Dog | Cat | Cat | ||||||
7 | Dog | Cat | Bird | ||||||
8 | Dog | Bird | Dog | ||||||
9 | Dog | Bird | Cat | ||||||
10 | Dog | Bird | Bird | ||||||
11 | Cat | Dog | Dog | ||||||
12 | Cat | Dog | Cat | ||||||
13 | Cat | Dog | Bird | ||||||
14 | Cat | Cat | Dog | ||||||
15 | Cat | Cat | Cat | ||||||
16 | Cat | Cat | Bird | ||||||
17 | Cat | Bird | Dog | ||||||
18 | Cat | Bird | Cat | ||||||
19 | Cat | Bird | Bird | ||||||
20 | Bird | Dog | Dog | ||||||
21 | Bird | Dog | Cat | ||||||
22 | Bird | Dog | Bird | ||||||
23 | Bird | Cat | Dog | ||||||
24 | Bird | Cat | Cat | ||||||
25 | Bird | Cat | Bird | ||||||
26 | Bird | Bird | Dog | ||||||
27 | Bird | Bird | Cat | ||||||
28 | Bird | Bird | Bird | ||||||
Sheet3 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
E2:G28 | E2 | =PermutX(A2:A5,C2) |
Dynamic array formulas. |
Name Manager Lambda function "PermutX"
Excel Formula:
=LAMBDA(
range,
repetition,
LET(v,range,
c,COUNTA(v),
n,MID(TEXT(BASE(SEQUENCE(PERMUTATIONA(c,c),,0),c),REPT("0",c)),SEQUENCE(,c),1)+1,
pa,INDEX(v,n),nj,BYROW(pa,LAMBDA(ro,TEXTJOIN(,,ro))),
f,BYROW(nj,LAMBDA(ro,SUM(IF(LEN(ro)-LEN(SUBSTITUTE(ro,v,"")),1,0))=c)),
IF(repetition,pa,FILTER(pa,f))
)
)