#!perl $b = ++$/ x 11 . <>; # $/='1' (not present in input). Slurp STDIN. # Prepend '11111111111' 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 ' ' place 'x' in a copy of board. while( $x=~/w/g ) { # Consider each 'w' in turn and $_ = "$`W$'"; # copy board highighing that 'w' as 'W'. 1 while # Until you run out, s/w((?<=W.{10})|(?<=W.)|(?=.{9}W|W))/W/s; # highlight a neighbouring 'w'. /W((?<= .{10})|(?<= .)|(?=.{9} | ))/s # Find a 'W' neighbouring a ' '. || # If there is no such peg we have captured. $i=~/./ + # Split row number out of cell number. (print"$& $'\n") + # Print row and colunm. last # Advance to next possible cell. } } }