Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
100 prisoners' problem
#10
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"

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.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
100 prisoners' problem - by TempodiBasic - 04-15-2023, 10:44 AM
RE: 100 prisoners' problem - by bplus - 04-15-2023, 02:18 PM
RE: 100 prisoners' problem - by SMcNeill - 04-15-2023, 02:31 PM
RE: 100 prisoners' problem - by TempodiBasic - 04-16-2023, 11:04 AM
RE: 100 prisoners' problem - by SMcNeill - 04-16-2023, 02:41 PM
RE: 100 prisoners' problem - by bplus - 04-15-2023, 05:41 PM
RE: 100 prisoners' problem - by SMcNeill - 04-15-2023, 07:08 PM
RE: 100 prisoners' problem - by bplus - 04-16-2023, 02:32 PM
RE: 100 prisoners' problem - by SMcNeill - 04-16-2023, 03:25 PM
RE: 100 prisoners' problem - by bplus - 04-17-2023, 07:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  100 lines or less... Unseen Machine 17 1,392 11-01-2025, 10:33 AM
Last Post: MasterGy
  Mystery Mania an 80's Logic Problem Generator justsomeguy 4 1,104 02-09-2025, 08:18 PM
Last Post: justsomeguy
  start.command problem on macOS tothebin 3 1,116 04-29-2024, 01:16 AM
Last Post: NakedApe
  A program to solve a problem: filter Linux/Unix 'ls' output TDarcos 1 760 07-15-2023, 12:29 AM
Last Post: grymmjack

Forum Jump:


Users browsing this thread: 1 Guest(s)