Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
reg.ru sponsors of YAPC::EU::2013 set this challenge based on the game of Go:
  1. Problems are given for a Go training board with the size of 9×9.
  2. Black moves first.
  3. There are no stones already captured on the board.

Input: nine lines which represent the playing board are sent to STDIN. Lines consist of spaces (for vacant points on the board), "w" symbols (for white stones) and "b" symbols (black stones) and end with the new line symbol ("\n").

Output: сoordinates (row and column numbers separated with a space, counted from one) of points, a move to which results in the capture of white stones. Results must be sent to STDOUT, one point per line. Results must contain all the possible moves on the board which would lead to the capture of white stones. Points are to be output in the order of their position on the board (left to right, top to bottom).

This is my first attempt at Perl-golf and (because BooK wasn't here this year) I actually won with 205 characters. (Woo hoo!)

#!perl $b=++$/x11 .<>;for$i(9..99){if(($x=$b)=~s/^(.{$i}) /$1x/s){while($x=~/ +w/g){$_="$`W$'";1while s/w((?<=W.{10})|(?<=W.)|(?=.{9}W|W))/W/s;/W((?<= .{10})|(?<= .)|(?=.{9 +} | ))/s||$i=~/./+(print"$& $'\n")+last}}}
Or with comments and whitespace
#!perl $b = ++$/ x 11 . <>; # $/='1' (not prese +nt in input). Slurp STDIN. # Prepend '11111111 +111' so top left is at 11. # Leave the "\n" in + to act as border and make # rows 10 so linear + pos is also row/col. for $i (9..99) { # Scan all possible + cells (including border). if( ($x=$b) =~ s/^(.{$i}) /$1x/s ) { # If cell is ' ' pl +ace 'x' in a copy of board. while( $x=~/w/g ) { # Consider each 'w' + in turn and $_ = "$`W$'"; # copy board high +ighing that 'w' as 'W'. 1 while # Until you run out +, s/w((?<=W.{10})|(?<=W.)|(?=.{9}W|W))/W/s; # highlight a nei +ghbouring 'w'. /W((?<= .{10})|(?<= .)|(?=.{9} | ))/s # Find a 'W' neighb +ouring a ' '. || # If there is no su +ch peg we have captured. $i=~/./ + # Split row number +out of cell number. (print"$& $'\n") + # Print row and col +unm. last # Advance to next p +ossible cell. } } }

Improvements from the Monks welcome.


In reply to YAPC::EU::2013 reg.ru Go Perl golf contest by nobull

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-16 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found