Think about the last state
Mathematica Stackexchange remains a wonderful resource for answering questions and learning from experts.
I posed my theatre problem issues and almost immediately (well, given at the moment I have poor internet connectivity on a cold mountain top it seemed that way to me) got the most wonderful solutions (I emphasize the plural) from Mr.Wizard.
Instantaneously, I felt the shame of my nested conditionals with their amplifying recursion number; my lack of patience with the Law of Large Numbers(perhaps to paraphrase Jaws, “better get a bigger sample”), However, looking at the solutions I learned (and hope to learn more as I contemplate them).
I was particularly enthused by the following:
sim4 =
Compile[{{n, _Integer}},
Module[{seats, trys},
seats = ConstantArray[0, n];
trys = RandomSample @ Partition[Range@n, 2, 1];
Do[If[seats[[i]] === {0, 0}, seats[[i]] = {1, 1}], {i, trys}];
Tr @ seats
]
];
This was neat; and does all the right things as the following graphics from my playing with it attest. My summary of the code by Mr. Wizard:
- . Make a constant ary of zeroes to represent empty seats
- Generate a random partition of
Range[n]of size two with offset 1. This generates a possible final theatre set of side by side seats and the sample elements are just the part indices for theseats - Fill empty side by side seats from your random sample
- Use Magthematica’s generalised trace to sum to
1s for the filled seats - The answer is just the complement normalized to
n
The following is histogram of 1000 runs for 10000 seat theatre:
The mean and standard deviation respectively: 0.135379, 0.00275046. ()
The following are ten plots of simulations of increasing theatre size:

It is gratifying when things make sense and wonderful when you learn in the process…peace to all this time of year and solace to those experiencing so much suffering from natural disasters and unexplainable human actions…

Note: