Permalink
Browse files

code clean up and removed if() at the expense of flipping the blue card

  • Loading branch information...
1 parent 620ffb0 commit a13afcd22f3ca26c9b88f811ec5a0ceb4ffde201 @outofjungle committed Mar 13, 2013
Showing with 11 additions and 8 deletions.
  1. +11 −8 game.pl
View
19 game.pl
@@ -1,5 +1,6 @@
#!/usr/bin/env perl
+use strict;
use constant THRESHOLD => 10000;
my $stack = {
@@ -25,16 +26,18 @@ sub flip {
my $count = {};
do {
- $face = draw( $stack );
- $color = $stack->{$face};
+ my $face = draw( $stack );
+ my $color = $stack->{$face};
$count->{$color}->{count}++;
- if ( $color eq 'red' ) {
- $face = flip( $face );
- $color = $stack->{$face};
- $count->{red}->{$color}->{count}++;
- }
+ $face = flip( $face );
+ my $flip_color = $stack->{$face};
+ $count->{$color}->{$flip_color}->{count}++;
+
} while ( $count->{red}->{count} < THRESHOLD );
-printf ( "%f\n", $count->{red}->{red}->{count} / $count->{red}->{count} );
+printf (
+ "(# red second draw )/(# red first draw red ): %f\n",
+ $count->{red}->{red}->{count} / $count->{red}->{count}
+);

0 comments on commit a13afcd

Please sign in to comment.