Advertisement
Guest User

Stats SE 90004 Perl

a guest
Mar 14th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.13 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use POSIX;
  5.  
  6. my $numRuns = 100000;
  7. my $rangeMax = 100;
  8. my $numPicks = 25;
  9. my $countTies = 0;
  10.  
  11. for (my $run = 0; $run < $numRuns; $run++) {
  12.     my @picks;
  13.     #print "Run " . ($run+1) . ": ";                                                                                                                                                                                  
  14.     for (my $pick = 0; $pick < $numPicks; $pick++) {
  15.         #push a new value onto the list, make it an int for viewability's sake                                                                                                                                        
  16.         push @picks, ceil(rand($rangeMax));
  17.     }
  18.     @picks = sort {$a < $b} @picks;
  19.     #print "@picks\n";                                                                                                                                                                                                
  20.     if ($picks[0] == $picks[1]) {$countTies++;}
  21. }
  22. print "Number of ties: $countTies\n";
  23. my $result = $countTies/$numRuns;
  24. print "Result: $result\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement