Created
January 27, 2019 08:21
-
-
Save tomcha/b71b23106dd1ddaeea113d248d1fdbc7 to your computer and use it in GitHub Desktop.
card_simulator
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/env perl | |
use strict; | |
use warnings; | |
use feature 'say'; | |
my @player_a = (1, 5, 10); | |
my @player_b = (2, 2, 2); | |
my %winer = ( | |
pa => 0, | |
pb => 0, | |
draw => 0, | |
); | |
print "How many times try it ? >>>"; | |
chomp(my $times = <STDIN>); | |
for (1..$times){ | |
for (1..3){ | |
my $num = int(rand(40)) + 1; | |
@player_a = matching($num, \@player_a); | |
@player_b = matching($num, \@player_b); | |
} | |
if (!@player_a){ | |
$winer{pa} += 1; | |
} | |
elsif (!@player_b){ | |
$winer{pb} += 1; | |
} | |
else{ | |
$winer{draw} += 1; | |
} | |
} | |
say "player_a win:$winer{pa}, player_b win: $winer{pb}, draw: $winer{draw}"; | |
sub matching{ | |
my $n = shift; | |
my $player_cards = shift; | |
my @result; | |
for my $card (@$player_cards){ | |
if ($card != $n){ | |
push(@result, $card); | |
} | |
} | |
return @result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment