In setting up a game playing program to allow easy addition of patterns (see X -> do Y), I discovered the complete list of patterns for this puzzle:

  1. Find a square that, if you plant a tree there, will cause the elimination of at least one color. Mark that square as unavailable.
  2. Repeat step 1. until solved.


That's it :)

Here's the code for it:

#!/usr/bin/perl # http://perlmonks.org/?node_id=1207779 use strict; use warnings; print local $_ = my $grid = <<END, "starting\n"; GRBBB GRBBW ORBBW OOOWW OOOOW END my $N = $grid =~ /\n/ && $-[0]; my $n = $N - 1; sub clear # the no longer available squares { my $pick = qr/[a-z]/; local $_ = shift; 1 while s/\w(?=.*?$pick)/-/ + s/$pick.*?\K\w/-/ # row + s/\w(?=(?:.{$N}.)*.{$N}$pick)/-/s # column + s/$pick(?:.{$N}.)*.{$N}\K\w/-/s # column + s/$pick.{$n}(..)?\K\w/-/s # lower diagonals + s/\w(?=.{$n}(..)?$pick)/-/s # upper diagonals ; return $_; } sub missingcolor { $N > keys %{{ map +($_, $_), shift =~ /\w/g }} } while( /[A-Z]/g ) # mark square to '-' if tree there causes a missing +color { missingcolor( lc clear( "$`\l$&$'" ) ) and $_ = "$`-$'", print $_, ' ' x $N, " mark ", $-[0] % ($N + 1), ',', int $-[0] / ($N + 1), "\n"; # x,y coords } print s/[A-Z]/$&/g == $N ? "\nSolved!\n" : "Failed\n";

It prints a grid for each step of the solution (slightly more than 120 lines).


In reply to Re^3: Parks Puzzle by tybalt89
in thread Parks Puzzle by aartist

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.