Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: YAPC::EU::2013 reg.ru Go Perl golf contest

by Grimy (Pilgrim)
on Aug 21, 2013 at 21:09 UTC ( [id://1050421]=note: print w/replies, xml ) Need Help??


in reply to Re: YAPC::EU::2013 reg.ru Go Perl golf contest
in thread YAPC::EU::2013 reg.ru Go Perl golf contest

Variable-length negative look-behind can be emulated using \K. The two regexes are almost identical, and can be abstracted in a variable. "@-" is shorter than "$-[0]". If using perl >= 5.14, /./ followed by "$& $'" can be replaced with s/./$& /r.

All in all, that's 30 characters easily chipped off. There’s still a lot of room for improvement—this next is hurting my eyes. I’ll probably look at it some more another day.

#!perl -ln0 $:='(.{9}|)\Kw|w(?=(.{9}|)'; map{$i="@-"+11;{map{1while s/W$:W)/W/s;/ \U$: )/s||print($i=~s/./$& /r)+next}"$`W$'"while/w/g}}"$ +`x$'"while/ /g

Replies are listed 'Best First'.
Re^3: YAPC::EU::2013 reg.ru Go Perl golf contest
by Grimy (Pilgrim) on Aug 22, 2013 at 11:44 UTC
    Another 22 characters shaved off:
    #!perl -ln0 $:='((?=W|.{9}W)|(?<=W.)|(?<=W.{10}))';{1while s/w$:/W/s;/ $:/gs>//gs& +&print+("@-E-1"+1)=~y/./ /r;y/W/x/;s/w/W/&&redo}
    EDIT: Down to 109. I’m starting to like it, but we can likely get this under 100.
    #!perl -ln0 $,='((?=.(.{9})?g)|g(.{9})?\K)'until!s!$,w!g!s;$,=/$, /gs>//gs&&!map!y +!.! !>print,"@-e-1"+1;y&g& &&&redo
    EDIT2: While my first solution was correct, both solutions in this post have the same problem: if playing a single black stone captures multiple white groups, this move is printed multiple times. Here’s a 127 stroker that prints each move only once:
    #!perl -ln0 map{1while$,=s=$,w=g=s?'(g|(?=.g|..{9}g)|g.{9})\K':/g/>/$, /s&&map{y!. +! !;print;redo}/x/+"@+E-1"or y&g&b&}"$`x$'"while/ /g

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1050421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found