If you're going to play 52 Perl Pickup, you might as well use CPAN. :-)
use strict; use warnings; use Games::Cards; my $num_decks = 2; # Create a deck of cards my $game = Games::Cards::Game->new( {} ); # default game my $deck = Games::Cards::Deck->new( $game, 'Deck' ); $deck->shuffle; # Assemble the pile of cards my @pile; push( @pile, map { $_->print() } @{ $deck->cards } ) for 1 .. $num_dec +ks; my @sorted_pile = sort @pile; # Compute the number of decks in the pile (pretend we don't know it) my $num_decks_calc = scalar @sorted_pile / $deck->size; # Divide the pile into decks my @decks; while( @sorted_pile ) { foreach my $decknum ( 0 .. $num_decks_calc-1 ) { push( @{ $decks[$decknum] }, pop( @sorted_pile ) ); } } # Print the results foreach my $decknum ( 0 .. $num_decks_calc-1 ) { print join( ' ', @{ $decks[$decknum] } ), "\n\n"; }
Note: error checking could be added (missing cards, etc).
In reply to Re: 52 Perl Pickup
by bobf
in thread 52 Perl Pickup
by dogz007
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |