favorite horses
The editor, here, may wrap or unalighn the text.
The proper code occupies ~80 lines.
Copy & paste, then correct for text wrap.
Re-indent to make it pretty, again.
Sub fav__horses()
'by time*treat ~ Sat., Apr/21/2007'
Dim total__horses As Integer, num__of__faves As Integer
Dim gates() As Integer, row As Integer, col As Integer
Dim winners As Integer, losers As Integer
Dim win__val As Long, lose__val As Long
Dim horse As Integer, stall As Integer
Dim winner__gates() As Integer, loser__gates() As Integer
Dim W__conflict__flag As Boolean, L__conflict__flag As Boolean, c__num As Long
Const light__red As Integer = 38
Const light__green As Integer = 35
'good for up to 10 horses'
total__horses = 6: num__of__faves = 2
ReDim gates(total__horses)
winners = num__of__faves
losers = total__horses - num__of__faves
ReDim winner__gates(winners)
ReDim loser__gates(losers)
c__num = 0: Cells.Clear
'left side - arrangement of winners'
For win__val = 1 To 10 ^ winners - 1
W__conflict__flag = False
For horse = 1 To winners: winner__gates(horse) = 0: Next horse
For horse = 1 To winners
stall = Int((win__val Mod 10 ^ (winners + 1 - horse)) / 10 ^ (winners - horse))
If stall <= winners Then
If stall = 0 Or winner__gates(stall) <> 0 Then
W__conflict__flag = True
Exit For
Else
winner__gates(stall) = horse
End If
Else
W__conflict__flag = True
End If 'stall <= winners'
Next horse
If W__conflict__flag = False Then
'right side - arrangement of losers'
For lose__val = 1 To 10 ^ losers - 1
L__conflict__flag = False
For horse = 1 To losers: loser__gates(horse) = 0: Next horse
For horse = 1 To losers
stall = Int((lose__val Mod 10 ^ (losers + 1 - horse)) / 10 ^ (losers - horse))
If stall <= losers Then
If stall = 0 Or loser__gates(stall) <> 0 Then
L__conflict__flag = True
Exit For
Else
loser__gates(stall) = horse
End If
Else
L__conflict__flag = True
End If 'stall <= losers'
Next horse
If L__conflict__flag = False Then
c__num = c__num + 1
Cells(c__num + 1, 1).Value = "#" & c__num
For col = 1 To winners
Cells(c__num + 1, col + 1).Value = winner__gates(col)
Cells(c__num + 1, col + 1).Interior.ColorIndex = light__green
Next col
For col = 1 To losers
Cells(c__num + 1, col + 1 + num__of__faves).Value = loser__gates(col) + num__of__faves
Cells(c__num + 1, col + 1 + num__of__faves).Interior.ColorIndex = light__red
Next col
End If 'L__conflict__flag'
Next lose__val
End If 'W__conflict__flag'
Next win__val
Cells(1, 1).Value = "~" & c__num & "~"
Cells.EntireColumn.AutoFit
End Sub