<[EMAIL PROTECTED]> wrote:
>http://www.xs4all.nl/~thospel/golf/midigolf1.html
...
>(it finishes thursday night UT, so another 35 hours)

Okay, it's past midnight UTC by my clock.

Here's my 57, along with a brief explanation:




[ SPOILERS ]







[ SPOILERS ]





#!perl -lp0
$_+=s/(\w)(\C{10})?(?!\1)\w|^(.*)x/X$+X/?redo:/X.*$/



First we slurp the whole input into $_ with -p0. Then we execute the
substitution until it fails (looping with redo). When the substitution
fails,check whether the last line contains an X. If yes, print a 1
(using -p), otherwise a 0. -l takes care of the newline.

That just leaves the substitution, which is basically a two-parter:
s/(\w)(\C{10})?(?!\1)\w|^(.*)x/X$+X/
  111111111111111111111 222222

The first part checks for an x or X, followed by either 0 or 10
charatecters (including linebreaks), followed by another x or X. The
(?!\1) makes sure that the first and last \w match different
characters (i.e xx and XX won't be matched). The substitution part
just replaces both \w:s with X:s. I.e while there are x:s that are
adjacent to X:s on the grid, replace them with X:s.

Now, since the input starts out as [x \n]+, we need to get some X:s in
there for the substitution to do anything. The second part of the
regexp (|^(.*)x) basically searches for the last 'x' on the first line,
and replaces it with an X. As an side effect, an additional X is added
to the start of the line. That doesn't have any effect, except making
debug output harder to read.

A very nice problem. Can't wait to see the 55's.

-- 
Juho Snellman
"C:st� on kehitetty Massachusettsin teknillisess� korkeakoulussa kieli
 nimelt� BCPL."  

Reply via email to