Permutations with no Repetition and NO Duplicates

excelNewbie22

Well-known Member
Joined
Aug 4, 2021
Messages
510
Office Version
  1. 365
Platform
  1. Windows
hi,
i need a way to generate Permutations with no repeats, and no duplicates
either with a formula or an udf,

so if i have the numbers: 1-2-3-4 i'll get:
[1,2,3,4],[1,2,4,3],[1,3,2,4],[1,3,4,2],[1,4,2,3],[1,4,3,2],[2,1,3,4],[2,1,4,3],[2,3,1,4],[2,3,4,1],[2,4,1,3],[2,4,3,1],[3,1,2,4],[3,1,4,2],[3,2,1,4],[3,2,4,1],[3,4,1,2],[3,4,2,1],[4,1,2,3],[4,1,3,2],[4,2,1,3],[4,2,3,1],[4,3,1,2],[4,3,2,1]
ignore the brackets
total of 24 permutations with no duplicates

and, this is the problematic part, if i have 1-2-3-3 i want to get:
[1,2,3,3],[1,3,2,3],[1,3,3,2],[2,1,3,3],[2,3,1,3],[2,3,3,1],[3,1,2,3],[3,1,3,2],[3,2,1,3],[3,2,3,1],[3,3,1,2],[3,3,2,1]
total of 12 only, with no duplicates

and
if 1-2-2-2 i want to get: [1,2,2,2],[2,1,2,2],[2,2,1,2],[2,2,2,1] only 4 in total

found an udf in get-digital-help.com but it return duplicates,

also i have this:
Excel Formula:
=INDEX(A2:D2,MID(BASE(SEQUENCE(PERMUTATIONA(COUNTA(A2:D2),4))-1,COUNTA(A2:D2),4),SEQUENCE(,4),1)+1)
but it returned all premutations with duplicates and repetitions

can it be done?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How about
Fluff.xlsm
ABCD
1
21233
3
41233
51323
61332
72133
82313
92331
103123
113132
123213
133231
143312
153321
Master
Cell Formulas
RangeFormula
A4:D15A4=LET(d,A2:D2,c,COLUMNS(d),m,MID(BASE(SEQUENCE(c^c,,0),c,c),SEQUENCE(,c),1)+1,x,INDEX(d,FILTER(m,BYROW(m,LAMBDA(br,SUM(--(br=TOCOL(br)))=c)))),r,ROWS(x),b,BYROW(x,LAMBDA(br,CONCAT(br))),FILTER(x,MMULT((SEQUENCE(r)>=SEQUENCE(,r))*(b=TOROW(b)),SEQUENCE(r,,,0))=1))
Dynamic array formulas.
 
Last edited:
Upvote 0
you are an asset to this forum!
thank you, again!

you solved my problem,
and still, if i may,
is it possible to generate them joined instead of 4 cells each one?
like in cell E2-1233 and in F2-1323 and in G2-1332 and so on...
i had to ask
 
Upvote 0
Yup, you can do that like
Excel Formula:
=LET(d,A2:D2,c,COLUMNS(d),m,MID(BASE(SEQUENCE(c^c,,0),c,c),SEQUENCE(,c),1)+1,x,INDEX(d,FILTER(m,BYROW(m,LAMBDA(br,SUM(--(br=TOCOL(br)))=c)))),r,ROWS(x),b,BYROW(x,LAMBDA(br,CONCAT(br))),TOROW(FILTER(b,MMULT((SEQUENCE(r)>=SEQUENCE(,r))*(b=TOROW(b)),SEQUENCE(r,,,0))=1)))
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,069
Members
449,092
Latest member
ipruravindra

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