Created
May 15, 2009 01:53
-
-
Save junichiro/112021 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
use List::Util qw/shuffle/; | |
my $roop = 1000; | |
my $number = 100; | |
my $limit = 50; | |
my @persons = 1 .. $number; | |
my $success = 0; | |
foreach ( 1 .. $roop ) { | |
my $cards = [ shuffle 1 .. $number ]; | |
$success++ if ( is_success($cards) ); | |
} | |
print $success / $roop, "\n"; | |
sub is_success { | |
my $cards = shift; | |
my $is_ok = 0; | |
PERSON: foreach my $num (@persons) { | |
my $my_num = $num; | |
CARD: foreach ( 1 .. $limit ) { | |
$num = $cards->[ $num - 1 ]; | |
next CARD unless ( $my_num eq $num ); | |
$is_ok++; | |
next PERSON; | |
} | |
} | |
return ( $is_ok eq $number ) ? 1 : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment