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

[FWP] Re: Golf: chessboard



In article <20010304205418.0A0AE23193@server3.safepages.com>,
	"Keith Calvert Ivey" <kcivey@cpcug.org> writes:
> Ton Hospel <fun_with_perl@ton.iguana.be> wrote:
> 
>> Ok, first attempt:
>> 
>> $_=pop;s/\d/$|x$&/eg;s/./--$|?$&||$":$&||"."/eg;y|/|\n|;print
> 
> I knew there was way to use $| for a toggle, but for some 
> reason I couldn't figure it out last night.  That and filling 
> the empty squares with 0s initially are the sort of creativity 
> I was hoping for.
> 
> Unfortunately, you're missing the spaces between columns and 
> (unless you're using -l) the newline at the end.

Yeah, I missed the spaces even when comparing my solution to your
examples. I found some better ways to use $|, but they all end up around
63 chars or something. 

Here's a completely non-portable one:
#! /usr/bin/perl -l
$_=pop;s/\d/$"x$&/eg;$_|="^@@"x35;y|`/o|.\n|;s/./$& /g;print

That ^@ is a binary 0. replace it by \0 if you find that too abusive.
59 characters.

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