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

Re: [FWP] APL vs. Perl. A query from a lazy programmer.



Keith Calvert Ivey wrote:
> 
> Richard Proctor <Richard@waveney.org> wrote:
> 
> > This looks a fun game...  Here is my initial offering (at 181 - not yet
> > down to APL).
> >
> > for$s(@s=qw/S H D C/){for(split//,"AKQJT98765432"){
> > redo if++$t[$h=3&rand 4]>13;${$s.$h}.=$_}};
> > for(0..2){for$s(@s){
> > printf$_&1?("$s: %-21s",${$s.3}):" "x12;print"$s: ".${$s.$_}."\n"}}

Why have I not seen this yet?
 
> Down to 173 with some trivial changes:
> 
>   for$s(@s=(S,H,D,C)){for(split//,AKQJT98765432){
>   redo if++$t[$h=3&rand 4]>13;${$s.$h}.=$_}}
>   for(0..2){for$s(@s){
>   printf$_&1?("$s: %-21s",${$s.3}):$"x12;print"$s: ".${$s.$_}.$/}}

> As the cards are distributed in order, consider what happens as
> players' hands start to fill up.  The clubs (which come last)
> will be distributed strangely; the most obvious problem is that
> the 2 and 3 of clubs are too likely to go to the same person.

Yes, but if you reject the whole distribution instead of trying to fit
the clubs in then that problem will go away (though it will be slower).
You will only take those random distributions that happen to fall out
into 4 hands of 13.

> If there's a way to simulate a deal by handling one suit at a
> time, it's got to be more complicated than this.

Maybe I'm missing something?

  A:{@t=%k=();for$s(@s=(S,H,D,C)){for(split//,AKQJT98765432){
  redo A if++$t[$h=3&rand 4]>13;$k{$s.$h}.=$_}}}
  for(0..2){for$s(@s){
  printf$_&1?("$s: %-21s",$k{$s.3}):$"x12;print"$s: ".$k{$s.$_}.$/}}

which weighs in at 191.

-- 
Rick Delaney
rick.delaney@home.com

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