There's more than one way to do things PerlMonks

### comment on

 Need Help??

The question is where you want to draw the line between finding the solution and providing information about the solution. Based on the encoding of the states of the world used in the code above (represented by \$s), the expression

grep!\$s{\$_}&!(\$s&8&&~\$s&\$_&7)&!(~\$s&8&&\$s&~\$_&7)&&(\$z=\$s^\$_)&8&&((\$z&= +7)<3|\$z==4),15,grep\$_%3,1..14

is used to find the next possible moves based on the rules given. It constructs the following implicit tree:

0-8 11-1 7-15 \ / \ / 10-2 13-5 \ / 14-4

Already, I have excluded states 3, 6, 9 and 12 as in thoses states something gets eaten. Looking at this tree, the problem is to find a path from "0" to "15" which is rather simple.

The question is how much of this information is allowed to be input to the script rather being calculated. In the extreme, one could just provide the two solutions and find the shortest script to print them without having to bother moving boats, wolfs, cabbages and goats. But that would be not very interesting...

And to clarify: the grep expression is not an obfuscated version of the tree but finds possible moves based upon the rules (\$s is where we are, \$_ a possible next state):

grep !\$s{\$_} # we have not been at \$_ already &!(\$s&8 # prohibit the boat is on the right bank initia +lly &&~\$s&\$_&7) # and a move from left to right &!(~\$s&8 # prohibit the boat is on the left bank initial +ly &&\$s&~\$_&7) # and a move from right to left &&(\$z=\$s^\$_)&8 # the boat moves &&((\$z&=7)<3|\$z==4), # with at most one passenger 15,grep\$_%3,1..14 # possible choices for moves

In reply to Re^5: Golf: Cabbage, Goat, Wolf by hdb
in thread Golf: Cabbage, Goat, Wolf by educated_foo

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 or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-11-27 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?