Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Last active July 25, 2017 21:34
Show Gist options
  • Save briandfoy/de67110e8adf3f06be77aced0289984e to your computer and use it in GitHub Desktop.
Save briandfoy/de67110e8adf3f06be77aced0289984e to your computer and use it in GitHub Desktop.
Perl 6 poker hand generator (but not scorer)
#!/Applications/Rakudo/bin/perl6
my $ranks = ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' );
my $suits = < ♣ ♡ ♠ ♢ >;
( @$ranks X @$suits )
==> map { [~] @$_ } \
==> my @cards;
;
my $player_count = 5;
my @hands = @cards.pick( $player_count * 2 + 5 );
my $players = @hands.head( $player_count * 2 ).rotor: 2;
my $community = @hands.tail(5).cache;
my $flop = $community.head: 3;
my $turn = $community.tail(2).head;
my $river = $community.tail: 1;
say "Players " ~ $players.gist;
say "Community: $community";
say "\tFlop: $flop";
say "\tTurn: $turn";
say "\tRiver: $river";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment