Finding possible combinations

985 Views Asked by At

Sorry if this isnt the right place to ask but heres my problem

I have a 6 digit combination that uses these 5 numbers (2,5,6,8,0). One of these numbers will have to be used twice. How would i go about getting a list of all possible combinations of these 5 numbers being used in a 6 digit combination

1

There are 1 best solutions below

0
On

Number of possible combinations are 5*(6!/2!) = 1800 (credit to @JMoravitz in the comments)

Here's a simple python code that provides you all combinations (you may run it here)

from itertools import permutations  

p = [2,5,6,8,0]
q = [2,5,6,8,0]

my_set = set()

index =0 
for i in q:
    p.append(i)
    perm = permutations(p,6) 

    for x in list(perm): 
        if x in my_set:
            continue

        my_set.add(x)
        print (index,x)
        index += 1

    p.remove(i)

snapshot result:

...
1784 (8, 5, 2, 6, 0, 0)                                                                                                                                                
1785 (8, 5, 6, 0, 2, 0)                                                                                                                                                
1786 (8, 5, 6, 0, 0, 2)                                                                                                                                                
1787 (8, 5, 6, 2, 0, 0)                                                                                                                                                
1788 (8, 6, 0, 2, 5, 0)                                                                                                                                                
1789 (8, 6, 0, 2, 0, 5)                                                                                                                                                
1790 (8, 6, 0, 5, 2, 0)                                                                                                                                                
1791 (8, 6, 0, 5, 0, 2)                                                                                                                                                
1792 (8, 6, 0, 0, 2, 5)                                                                                                                                                
1793 (8, 6, 0, 0, 5, 2)                                                                                                                                                
1794 (8, 6, 2, 0, 5, 0)                                                                                                                                                
1795 (8, 6, 2, 0, 0, 5)                                                                                                                                                
1796 (8, 6, 2, 5, 0, 0)                                                                                                                                                
1797 (8, 6, 5, 0, 2, 0)                                                                                                                                                
1798 (8, 6, 5, 0, 0, 2)                                                                                                                                                
1799 (8, 6, 5, 2, 0, 0)  
  • remember that the index start from position 0 (hence 1799+1 results)