A drawer contains a mixture of red socks and blue socks, at most 2014 in total. It so happens that, when two socks are selected randomly without replacement, there is a probability of precisely 2/3 that both are red or both are blue.
What is the maximum possible number of red socks in the drawer that is consistent with this data?
From highest to lowest total, each line is the total number of socks, the smaller color count and the larger color count (either could be red or blue):
1350 285 1065
361 76 285
96 20 76
25 5 20
6 1 5
so the maximum number of red socks is 1065 (out of 1350 socks, 285 of them blue).
from
For n = 2014 To 3 Step 1
r = Int(n / 2)
b = n  r
Do
pdiffnum = 2 * r * b
pdiffden = (n * (n  1))
' p = 1/3 of red then blue or blue then red
If 3 * pdiffnum = pdiffden Then
Text1.Text = Text1.Text & n & Str(r) & Str(b) & crlf
DoEvents
Exit Do
ElseIf 3 * pdiffnum < pdiffden Then
Exit Do
Else
r = r  1: b = b + 1
If r < 1 Then Exit Do
End If
Loop
Next

Posted by Charlie
on 20141106 11:05:58 