View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Sandy Mann
 
Posts: n/a
Default Tennis set combinations

Bernie,

In XL97 your code chokes on:

splResult = Split(Result, " ")

with *Split* hilighted and saying "Sub or function not defined". Asking
Help about *Split* brings up the page about Splitting the window. May I ask
what *Split* does in later versions of XL?


--
Regards

Sandy

with @tiscali.co.uk


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Raigmore,

Well, we can brute force it. Run the macro below, with a blank sheet
active.

This assumes that you aren't using the "Must win by 2 games" rule -
otherwise, there's an infinite number of combinations.

With that assumption, the set ends after a maximum of 11 games, with a
winner guaranteed. There are 924 possible combinations.

HTH,
Bernie
MS Excel MVP

Sub BruteForce()
For i = 1 To 11
Cells(1, i).Value = "Game " & i
Next i
Cells(1, 12).Value = "Winner"

RCount = 2
For a = 1 To 2
For b = 1 To 2
For c = 1 To 2
For d = 1 To 2
For e = 1 To 2
For f = 1 To 2
For g = 1 To 2
For h = 1 To 2
For i = 1 To 2
For j = 1 To 2
For k = 1 To 2

Result = a & " " & b & " " & c & " " & d & _
" " & e & " " & f & " " & g & " " & h & _
" " & i & " " & j & " " & k

splResult = Split(Result, " ")

Count1 = 0
Count2 = 0

For m = LBound(splResult) To UBound(splResult)
If CInt(splResult(m)) = 1 Then
Count1 = Count1 + 1
Else
Count2 = Count2 + 1
End If
Next m

If Count1 = 6 Then
For n = LBound(splResult) To UBound(splResult)
Cells(RCount, n + 1).Value = splResult(n)
If splResult(n) = 1 Then Count1 = Count1 - 1
If Count1 = 0 Then GoTo Written1
Next n
Written1:
Cells(RCount, 12).Value = 1
RCount = RCount + 1
End If

If Count2 = 6 Then
For n = LBound(splResult) To UBound(splResult)
Cells(RCount, n + 1).Value = splResult(n)
If splResult(n) = 2 Then Count2 = Count2 - 1
If Count2 = 0 Then GoTo Written2
Next n
Written2:
Cells(RCount, 12).Value = 2
RCount = RCount + 1
End If

Next k
Next j
Next i
Next h
Next g
Next f
Next e
Next d
Next c
Next b
Next a

Cells.EntireColumn.AutoFit
End Sub



"Raigmore" wrote
in message ...

I would be grateful for help with listing all the possible game
combinations within a set of tennis.

I just need to list all the possible combinations of which player (1 or
2) wins each game.

So for 6-0 to a player it is obviously 1,1,1,1,1.

6-1 can be 1,1,1,1,1,2,1 etc

Is there a way excel can list all the possible combinations?

Even if I just have a combination of all the ways 1 and 2 can win in a
12 game period.

I guess it is just 2*2*2*2*2 etc but how do I list it in 1s and 2s?


Hope this is clear!


--
Raigmore
------------------------------------------------------------------------
Raigmore's Profile:
http://www.excelforum.com/member.php...o&userid=30071
View this thread:
http://www.excelforum.com/showthread...hreadid=497492