This is a Python code I wrote to calculate the probability of a set of prisoners escaping based on this riddle from a Veritasium video https://www.youtube.com/watch?v=iSNsgj1OCLA.
The code uses Monte Carlo method to determine the probability of encountering a situation where no group has more than 50 loops. The result turns out to be around 0.33.