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

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



Ian Phillipps <igp_list2@tesco.net> wrote:
>The topic of APL came up today, and I recalled an APL one-liner (about
>150 chars if I recall) that printed a set of 4 Bridge hands in the
>conventional layout.
>
>Having more laziness and impatience than hubris at the moment, I
>wondered if fwpers would rise to the challenge of duplicating this
>feat...

The following is NOT -w safe. :)  It's also much longer than the challenge 
spec.  I'm sure it could be made grievously more obscure.

   #! perl
   @s=qw(S H D C);@r=(2..9,qw(T J Q K A));@u=0..51;push @c,
   splice(@u,rand@u,1)while@u;push @{$h[$c++/13]->{$s[$_%4]}}
   ,$_ for@c;sub h($){join '',map{$r[$_/4]}sort{$b<=>$a}@{$_[0]}}
   $p=' 'x15;$f='%s: %-13s';for$s(@s){$o[$n+$_+$_*7]=sprintf
   "$p$f\n",$s,h$h[$_]->{$s}for 0..1;$o[$n+++4]=sprintf
   "$f$p$f\n",$s,h$h[2]->{$s},$s,h$h[3]->{$s};}print @o;

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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