[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Perl Card Games



Chip Turner <chip@zfx.com> writes:

> Algorithm:
> 
> @cards = (1 .. 52);
> $shuffles = 8;
> while ($shuffles--) {
>   @a = @cards[0 .. @cards/2 - 1];
>   @b = @cards[@cards/2 .. @cards - 1];
>   @cards = map { ($a[$_], $b[$_]) } (0 .. $#a);
> }
> 
> print "@cards\n";

Much nicer version:
@cards = (1 .. 52);
$shuffles = 3;
@cards = map { ($cards[$_], $cards[$_ + @cards/2]) } (0 .. @cards/2 - 1)
  while $shuffles--;

I wonder if it qualifies as a sickness when you followup your own
message with a shorter version of something you wrote... :)

Chip

-- 
Chip Turner                   chip@ZFx.com
                              Programmer, ZFx, Inc.  www.zfx.com
                              PGP key available at wwwkeys.us.pgp.net

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe