-
-
Save anonymous/45202bfd81a2a8dbdf87 to your computer and use it in GitHub Desktop.
Monte-Carlo-Solution for masak's mini-challenge at http://irclog.perlgeek.de/perl6/2013-01-03#i_6294536
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for 1..* -> $N { | |
my $sum = 0; | |
my $count = $N**2; | |
for ^$count { | |
my @f = (^$N).pick(*); | |
my %seen; | |
%seen{0} = True; | |
my $current = 0; | |
repeat { | |
$current = @f[$current]; | |
$sum++; | |
} while !%seen{$current}; | |
} | |
say join "\t", $N, $sum / $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment