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

Re: [FWP] Golf: chessboard



abigail@foad.org wrote:

> 72 characters, without the shebang line. (^I is counted as one char):
> 
>    #!/opt/perl/bin/perl -li1
>    map{s/\d/$"x$&/eg;$^I++;print map{$^I++%2&&/$"/?'.':$_,$"}/./g}pop=~/\w+/g

The one I had before posting the challenge was 70 characters, 
with no command-line or shebang-line switches or control characters:

    $_=pop;s/\d/$"x$&/ge;$i^=1,print/\//?$/:/ /&&!$i?'. ':"$_ "for/./g,'/'

There are a few places that allow variation:

    $_=pop;s/\d/$"x$&/ge;$i%=2,print/\//?$/:/\w/||$i?$_.$":'. 'for/./g,'/'

> It does print a space before the newline though. If that's not allowed, 
> I might need three more characters.

Whitespace is okay with me as long as it's invisible.  That is, a 
reasonable amount (not enough to wrap) before the newline is acceptable.  
Most people certainly had plenty of spaces before the newlines in their
bridge solutions.

> I can also go down to 72 characters without using control char variables,
> but then you have to allow for command line switches:
> 
>     #!/opt/perl/bin/perl -ls
>     map{s/\d/$"x$&/eg;$i++;print map{$i++%2&&/$"/?'.':$_,$"}/./g}pop=~/\w+/g
> 
> which should be called as:
> 
>     chessboard -i=1 <position>

Actually, when I posted the challenge I wasn't thinking about switches of 
any kind -- I guess because for some reason no one used any in the bridge 
problem.  If I were doing it again I'd either prohibit them or make them 
count toward the total.  Is there any established convention for scoring 
golf problems that aren't one-liners?

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC

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