There are 5 students S
1, S
2, S
3, S
4, S
5 in a music class and for them there are 5 seats in a row. On examination day, all five students are randomly allotted the five seats.
What is the probability that no student is seated next to another student with a number that differs by 1?
DefDbl A-Z
Dim crlf$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
s$ = "12345": h$ = s
Do
good = 1
For i = 1 To 4
If Abs(Val(Mid(s, i, 1)) - Val(Mid(s, i + 1, 1))) = 1 Then good = 0: Exit For
Next
If good Then ct = ct + 1
permute s
Loop Until s = h
Text1.Text = Text1.Text & ct & " done"
End Sub
finds that 14 of the 5!=120 permutations have no adjacencies that differ by 1, for a probability of 7/60.
|
Posted by Charlie
on 2019-05-10 14:15:08 |