lock combination exercise

Bigslim

New Member
Joined
May 3, 2011
Messages
17
OK here is the example I want to create - imagine having a 4digit combination lock, and you want to know all the different combinations it could be. You want them printed seperately so you can see them all.

Now what I am doing involves the same concept only I need to get all the unique combinations where one is not being repeated more than once going backwards or forward.

ie. 0001 = 0010= 0100=1000 all these translate into 1 unique combination.

I want to host a series of games where I have 32 players, 8 teams of 4 players, divided into 4 tables. each week the player combination changes. And having one table be the same as the previous weeks will not work. The series is a 24 week series. And I also can't have the same team members playing at the same table.

I have started with "=index(array,Mrand()+1) after creating a list of all the teams and their players but I'm stuck because, I am going to have to check manually for repeats.

Any ideas would help. Thank you...Rich
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Here is a brute force VBA example which you may be able to adapt to your needs.

Code:
Sub PermutationsBruteForce()
Const kItems As Long = 9
Dim a As Long, b As Long, c As Long, d As Long, RowCount As Long
With ActiveSheet
    For a = 0 To kItems
        For b = 0 To kItems
            For c = 0 To kItems
                For d = 0 To kItems
                    RowCount = RowCount + 1
                    .Cells(RowCount, 1) = a
                    .Cells(RowCount, 2) = b
                    .Cells(RowCount, 3) = c
                    .Cells(RowCount, 4) = d
                Next d
            Next c
        Next b
    Next a
End With
End Sub
 
Upvote 0
As shg stated this is the stuff of phd theses.

You state two different problem, lock combination and social golfer.

"And I also can't have the same team members playing at the same table."

This could be social golfer, either 4 groups of 8 with the 8 divided into two teams,
in which case the pairings are counted at each table whether on the same team or not.
Or 8 groups of 4, where the pairings count only if on the same team.

Or there could be another variation of 8 groups of 4,
and also keep track of pairings across teams.
This is more complicated than the social golfer,
and there may be some literature on it but I have not seen it.

So perhaps you should consider what you may be getting into,
so that you can decide whether to tackle this problem,
or tackle something of comparable difficulty,
like maybe stowing away on the first manned mission to Mars.

Consider the 8 groups of 4 problem.

The number of pairings per Group is:
4-1 = 3
6=3+2+1
or:
6=4*(4-1)/2
48=8*6 Pairings per Row

Similarly there are:
496=32*31/2 possible pairings

Cell C1 = =B1/D$1 copy down
Cell D1 = 496


10 Rows is the maximum that has number of pairings of each<= 1 (0.967741935483871).
To get an integer number (3) go 31 Rows.

The solution of 10 Rows in the reference in the previous Post is:
MakePerfect020911-32-4.xls
ABCDEFGH
10102030405060708091011121314151617181920212223242526272829303132
20105132602080931030710300406152811202129121823321419242716172225
30107172102111324030618220410162305202530081928320914262912152731
40106113202071425030816270405122909172430101922311318212815202326
50108182402121621030920280411172705142232061926300713233110152529
60109152202051923031217260408132506142131071827291020243211162830
70112192502101826031114230407202205172831061624290815213009132732
80110142802062027032125320424263105091618071115190817232912132230
90116203102151732031319290414183005102127060923250712242808112226
100123273002222829030515240409192106101317071626320812142011182531
Sheet3

The pairing grid is:
MakePerfect020911-32-4.xls
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
10102030405060708091011121314151617181920212223242526272829303132
201XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3021XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
40311XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
504111XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6051111XXXXXXXXXXXXXXXXXXXXXXXXXXXX
70611111XXXXXXXXXXXXXXXXXXXXXXXXXXX
807111111XXXXXXXXXXXXXXXXXXXXXXXXXX
9081111111XXXXXXXXXXXXXXXXXXXXXXXXX
100911111101XXXXXXXXXXXXXXXXXXXXXXXX
1110111111101XXXXXXXXXXXXXXXXXXXXXXX
12111111011111XXXXXXXXXXXXXXXXXXXXXX
131211111011111XXXXXXXXXXXXXXXXXXXXX
1413111111111111XXXXXXXXXXXXXXXXXXXX
15141111111111111XXXXXXXXXXXXXXXXXXX
161511111111111111XXXXXXXXXXXXXXXXXX
1716111111111111111XXXXXXXXXXXXXXXXX
18171111111111111011XXXXXXXXXXXXXXXX
191811111111111111011XXXXXXXXXXXXXXX
2019111111111111111011XXXXXXXXXXXXXX
21201111111111110111111XXXXXXXXXXXXX
222111111111111111111111XXXXXXXXXXXX
2322111111111111111111111XXXXXXXXXXX
24231111111111111111111111XXXXXXXXXX
252411111111111111111111111XXXXXXXXX
2625111111111111111111111110XXXXXXXX
27261111111111111111111101111XXXXXXX
282711111111111111111111101111XXXXXX
2928111111111111111111111101111XXXXX
30290111111111111111111111111111XXXX
313010111111111111111111111111111XXX
3231110111111111111111111111111111XX
33321110111111111111111111111111111X
Sheet2

The number of Groups of 4 from 32 is 35960=COMBIN(32,4)
The number of combinations of 4 of the Groups is:
69,661,853,445,594,400=COMBIN(35960.4)
But only some of these will have all 32 Characters per Row.
This can be calculated as in:
Find and complete the series of numbers?</SPAN></SPAN>
http://www.mrexcel.com/forum/showthread.php?556229-Find-and-complete-the-series-of-numbers</SPAN>
Post 58.
1,579,413,859,773,750
The number of possible combinations of 10 Rows of these is:
COMBIN(1579413859773750,10) which gives an error.
Use logarithms to calculate.

COMBIN(1579413859773750,10)=LOG(1579413859773750)*10-LOG(FACT(10))
=145.425196414549

So the number of the possible combinations of 10 of the possible Rows is 10 to the 145.425196 power.
10 to the 0.425196 = 2.66
So the number of the possible combinations of 10 of the possible Rows is 2.662E+145.
Only a small fraction will be solutions.

The 10 Rows looks difficult,
but your question calls for going more Rows.
 
Upvote 0
Correction on the # of Combinations:

Cell A1:
=FACT(32)/FACT(28)/FACT(4)
Cell A2:A8:
=FACT(32-ROW(B1)*4)/FACT(28-ROW(B1)*4)/FACT(4)
Cell A9:
=PRODUCT(A1:A8)
Cell A10:
=A9/FACT(8)
=59,287,247,761,257,100,000

The number of possible combinations of 10 Rows of these is:
COMBIN(59287247761257100000,10) which gives an error.
Use logarithms to calculate.

COMBIN(59287247761257100000,10)=LOG(59287247761257100000)*10-LOG(FACT(10))
=191.2

So the number of the possible combinations of 10 of the possible Rows is 10 to the 191.2 power.

Not 10 to the 145.425196 power as in the Previous Post.

To use all 35960=COMBIN(32,4) elements sorted into Rows of 8 Elements,
where all characters appear on each Row,
there are 35960/8 = 4495 Rows.
This is a related variation of the problem that one of the Mrexcel members has worked on.
COMBIN(59287247761257100000,4495)=LOG(59287247761257100000)*4495-LOG(FACT(4495))

LOG(FACT(4495)) gives an error but:
LOG(FACT(4495))={=SUM(LOG(ROW(1:4495)))}

{LOG(59287247761257100000)*4495-SUM(LOG(ROW(1:4495)))}
=74410.37

So the possible combinations of 4495 Rows = 1E+74410.37
This does not consider whether an Element such as 02 07 21 32 can occur on more than one Row, which it cannot.
So the actual possible combinations,
as each Row is selected, is less than that.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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