Advertisement
Guest User

Stop once boy.

a guest
Dec 21st, 2010
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.56 KB | None | 0 0
  1. # For this: http://www.thebigquestions.com/2010/12/21/are-you-smarter-than-google/
  2.  
  3. my($tg, $tb) = (0, 0);
  4. my $fams = shift @ARGV || 10;
  5.  
  6. my $N=0;
  7. my @families = map { [0, 0] } (1 .. $fams);
  8.  
  9. while($tb < @families) {
  10.   for(my $i=0; $i<@families; $i++) { # 1000 couples trying for a boy
  11.     next if $families[$i][1];
  12.     if(rand() < 0.5) { # Girl
  13.       $families[$i][0]++;
  14.       $tg++;
  15.     } else {
  16.       $families[$i][1]++;
  17.       $tb++;
  18.     }
  19.   }
  20.   printf "Generation %d: girls=%d, boys=%d, ratio=%d%%\n", ++$N, $tg, $tb, 100 * ($tg / ($tg + $tb));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement