Skip to content

Instantly share code, notes, and snippets.

/carlo.pl Secret

Created January 3, 2013 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/45202bfd81a2a8dbdf87 to your computer and use it in GitHub Desktop.
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
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