The 100 doors example is a nice one-liner.
What about a way to visualize the door states over time? Here's a short program to do this:
use v6;
sub display-doors (\doors)
{
for doors { print $_ == True ?? '*' !! ' '; }
print "\n";
}
sub MAIN(\door-count, \passes, Bool :$random)
{
my \doors = [];
doors[^door-count] = $random ??
(loop { (True, False).pick }) !!
(loop { False });
display-doors doors;
for 1..passes -> \n
{
for doors[n-1, (n-1)+n ... *] { $_ = !$_ };
display-doors doors;
}
}
The program is called with the number of doors and how many passes over the doors to make:
The output sorta looks like elementary cellular automaton.
Let's run it again in xterm with "Tiny" font:
One more time with "Unreadable" font:
By default, the doors all start out closed. If you pass the --random
flag, they'll start out in a random state: