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

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



On Feb 16, Ian Phillipps said:

>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.

You made no mention of the data structure representing each hand (nor does
it sound like the code representing them counts in the printing).

Here's my code for the hands:

  @H = (
    [qw( AQJ83 KJ6   5     AQJ5 )],
    [qw( T6542 AT    QT762 4    )],
    [qw( K9732 9     974   A983 )],
    [qw( K7    Q8532 KJ4   T86  )],
  );

Yes, they're already sorted, and they're kept as strings.  If you want an
implementation using a hash of array refs, blah.

And here's the printer:

$A=(' 'x13).'@: @<<<<<<<<<<<<'."\n";$B='@: @<<<<<<<<<<<<       @: @<<<<<<<'.    
'<<<<<'."\n";for(@C=(S,H,D,C)){formline($A,$_,$H[0][$i++])}$^A.="\n";for(@C)
{formline($B,$_,$H[1][$j++],$_,$H[2][$j-1])}$^A.="\n";for(@C){formline($A,$_
,$H[3][$k++])}print$^A;

It's not beautiful, but it does the job.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/



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