In case anyone besides me wants to take a peek into the cycles created by random shuffles of 100 numbers here is my "100 Prisoners Group Analysis"
Sample Output of a Run:
Here Prisoner 3 failed to find es number in under 50 draws.
Code: (Select All)
_Title "100 Prisoners Group Analysis" ' b+ 2023-04-17
$Console:Only
Randomize Timer
Dim As Long slots(1 To 100), i, p, visit, c, cycleN
For i = 1 To 100
slots(i) = i
Next
Do
GoSub shuffle
Cls
ReDim As Long cycle(1 To 100), count(1 To 100)
cycleN = 0
For p = 1 To 100 ' prisoner number
If cycle(p) = 0 Then
c = 1
cycleN = cycleN + 1 ' new cycle number
cycle(p) = cycleN
visit = slots(p)
Print "Cycle Number:"; cycleN; " first visit "; visit;
While visit <> p
cycle(visit) = cycleN ' assign cycle number to number visit
c = c + 1
visit = slots(visit) ' get next number to visit
Print visit;
Wend
count(cycleN) = c
Print: Print
End If
Next
Print " Note: these cycles end on the prisoner number that started cycle."
Print: Print
For i = 1 To cycleN
Print "Cycle Number:"; i; " Visit Count:"; count(i)
Next
Print: Print " ...zzz"
Sleep
Loop Until _KeyDown(27)
End
shuffle:
For i = 100 To 2 Step -1
Swap slots(Int(Rnd * i) + 1), slots(i)
Next
Return
Sample Output of a Run:
Here Prisoner 3 failed to find es number in under 50 draws.
b = b + ...