I have 6 pieces of candy: two each of 3 different colors. They taste especially good if eaten two at a time, provided the colors are different.
These candies are in an opaque bag from which I pick two at a time. If they are different colors I eat them together (yum) but if they are the same I put them back in and draw again. I will repeat this process to eat two more.
What is the probability the last two candies will be of differing colors?
Repeat with two each of 4 colors.
Repeat with two each of 5 colors.
(In reply to
Second part by armando)
A simulation
DefDbl AZ
Dim crlf$
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For tr = 1 To 100000
clr$ = "aabbccdd"
Do
r1 = Int(Len(clr) * Rnd(1) + 1)
r2 = Int(Len(clr) * Rnd(1) + 1)
If Mid(clr, r1, 1) <> Mid(clr, r2, 1) Then
If r1 > r2 Then h = r1: r1 = r2: r2 = h
clr = Left(clr, r1  1) + Mid(clr, r1 + 1, r2  r1  1) + Mid(clr, r2 + 1)
End If
Loop Until Len(clr) = 2
If Left(clr, 1) <> Right(clr, 1) Then hitct = hitct + 1
Next
Text1.Text = Text1.Text & hitct / 100000
Text1.Text = Text1.Text & crlf & " done"
End Sub
comes up with
.87736
for part 2
and a variant produces
0.88996
for part 3
throwing in a randomize timer shows these results for part 2:
0.87865
0.87578
0.87658
on successive runs.
and for part 3,
0.89272
0.89239
0.89133

Posted by Charlie
on 20160525 21:05:17 