Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

setting up number combinations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lifeguardernie - 11 Oct 2007 17:14 GMT
how can i set it up so that i can have the program write out the combinations
between two numbers so that there are never the same number twice
and then add a third number to the equation

i need this for league teams
if i have for example 6 teams and i want them to play every other team
before repeating a team
then i want to add games into this combination so not only dont the play the
same team twice they go through all the games before repeating them again
Joel - 11 Oct 2007 17:58 GMT
Below is code I wrote for somebody else earlier this week.

Modify these two line as necessary
'you can make instring as long or short as you want.  You can put string in
the array instead of number.
'for 6 players
InStrings = Array(1, 2, 3, 4, 5, 6)
'for 10 players
InStrings = Array(1, 2, 3, 4, 5, 6,7,8,9,10)

modify for size of team or number of teams playing together
ComboLen = 2

Public InStrings
Public combo
Public RowCount
Public ComboLen
Sub combinations()

InStrings = Array(1, 2, 3, 4, 5, 6)
Length = UBound(InStrings) + 1

Level = 1
RowCount = 1
ComboLen = 2
ReDim combo(ComboLen)
Position = 0

Call recursive(Level, Position)
End Sub
Sub recursive(ByVal Level As Integer, ByVal Position As Integer)

Length = UBound(InStrings) + 1

For i = Position To (Length - 1)
 
  'for combinations check if item already entered
  found = False
  For j = 0 To (Level - 2)
     'combo is a count of the combinations,not the actual data
     '123
     '124
     '125
     '234
     '235
     '245
     '345
     'data is actually in InStrings
     If combo(j) = i Then
        found = True
        Exit For
     End If
  Next j
 
  If found = False Then
     combo(Level - 1) = i
     If Level = ComboLen Then
        For j = 0 To (ComboLen - 1)
           If j = 0 Then
              ComboString = InStrings(combo(j))
           Else
              ComboString = ComboString & "," & InStrings(combo(j))
           End If
        Next j
        Sheets("Sheet2").Range("A" & RowCount) = ComboString
        RowCount = RowCount + 1
     Else
        Call recursive(Level + 1, i)
     End If
  End If
Next i
End Sub

> how can i set it up so that i can have the program write out the combinations
> between two numbers so that there are never the same number twice
[quoted text clipped - 5 lines]
> then i want to add games into this combination so not only dont the play the
> same team twice they go through all the games before repeating them again
lifeguardernie - 18 Nov 2007 21:04 GMT
how do i actually apply this code in excel
i'm not used to them

> Below is code I wrote for somebody else earlier this week.
>
[quoted text clipped - 78 lines]
> > then i want to add games into this combination so not only dont the play the
> > same team twice they go through all the games before repeating them again
Joel - 18 Nov 2007 21:33 GMT
For 6 teams it is just easier to manually go through the combination.  try this

game 1: 1,2    3,4    5,6
game 2: 1,3    2,5    4,6
game 3: 1,4    2,6    3,5
game 4: 1,5    2,4    3,6
game 5: 1,6    2,3    4,5

> how do i actually apply this code in excel
> i'm not used to them
[quoted text clipped - 81 lines]
> > > then i want to add games into this combination so not only dont the play the
> > > same team twice they go through all the games before repeating them again
lifeguardernie - 20 Nov 2007 22:43 GMT
i did go through the combinations manually but i also need it tied to a
separate game
> game 1: 1,2   a    3,4   b    5,6   c
> game 2: 1,3    2,5    4,6
> game 3: 1,4    2,6    3,5
> game 4: 1,5    2,4    3,6
> game 5: 1,6    2,3    4,5

but while i could manually work out games and teams for 4 and 8 teams i cant
work out 6 teams

> For 6 teams it is just easier to manually go through the combination.  try this
>
[quoted text clipped - 89 lines]
> > > > then i want to add games into this combination so not only dont the play the
> > > > same team twice they go through all the games before repeating them again
Joel - 21 Nov 2007 12:20 GMT
Don'y you just want to rotate the columns?

game 1:    1,2    3,4    5,6
game 2:    1,3    2,5    4,6
game 3:    1,4    2,6    3,5
game 4:    1,5    2,4    3,6
game 5:    1,6    2,3    4,5

game 6:    5,6    1,2    3,4
game 7:    4,6    1,3    2,5
game 8:    3,5    1,4    2,6
game 9:    3,6    1,5    2,4
game 10:    4,5    1,6    2,3

game 11:    3,4    5,6    1,2
game 12:    2,5    4,6    1,3
game 13:    2,6    3,5    1,4
game 14:    2,4    3,6    1,5
game 15:    2,3    4,5    1,6

> i did go through the combinations manually but i also need it tied to a
> separate game
[quoted text clipped - 100 lines]
> > > > > then i want to add games into this combination so not only dont the play the
> > > > > same team twice they go through all the games before repeating them again
lifeguardernie - 21 Nov 2007 17:58 GMT
no what i want to do is within these five games have all the teams play a
different game so if by game one they play game a, by game two b, so nodody
does the same game twice

             teams-game-teams-game-teams-game
> game 1:    1,2    a      3,4        5,6
> game 2:    1,3    b      2,5       4,6
> game 3:    1,4    c      2,6       3,5
> game 4:    1,5    d      2,4       3,6
> game 5:    1,6    e        2,3       4,5

but manually it dosen't work out so i'm trying to figure out how to set it
up so the computer does all the work of making it fit

> Don'y you just want to rotate the columns?
>
[quoted text clipped - 120 lines]
> > > > > > then i want to add games into this combination so not only dont the play the
> > > > > > same team twice they go through all the games before repeating them again
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.