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

Re: [FWP] Golf: chessboard



Rick Klement wrote:
> 
> Keith Calvert Ivey wrote:
> >
> > The challenge is to write a Perl program with the fewest
> > characters (the shebang line doesn't count) that takes as a
> > command-line argument a chess position in Forsythe-Edwards
> > notation (FEN) and prints out an ASCII representation of a
> > chessboard like that produced by the Position->to_text() method
> > in Gareth Rees's Games::Chess module.
> >
> > My solution is less than 80 characters.  Good luck!
> >
> > --
> > Keith C. Ivey <kcivey@cpcug.org>
> 
> #!/usr/bin/perl -l
> $_=pop;
> s/\d/' 'x$&/eg;
> s/ (?=.(..)*$)/./g;
> s/./$& /g;
> s#/ #\n#g;
> print
> 
> 66 characters (if all on one line with no NLs)
> 
> This is probably too straightforward, but it's bedtime.
> I'll have to see what my subconscious can come up with...
> The Fun part is putting in the black squares.
> 
> --
> Rick Klement

Self improvement - 62 characters

#!/usr/bin/perl -l
$_=pop;s/\d/$"x$&/eg;s/ (?!(..)*$)/./g;y#/#\n#;s/./$& /g;print

-- 
Rick Klement

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