If you stretch your imagination enough (and Perl is good at letting that happen) you can solve these puzzles using Genetic algorithms.
You could assign each character in a string a task:
5 - fill 5 gallon bucket
3 - fill 3 gallon bucket
P - pour 5 into 3
p - pour 3 into 5
E - empty 5
e - empty 3
I don't think I'm missing anything. Your population would be strings of different lengths, maybe 3-10? I'm guessing here.
Then your fitness function takes the string, and just follows the instructions like a recipie. This does mean that some semi-impossible things could happen, empty an empty bucket, fill a full bucket etc.
Crossing is just taking random points in the string and swapping them.
Once you have a good GA engine it is easy to replace the fitness function and the population generation functions, and in a few cases the crossing function (mutation too!).
If I get bored sometime today maybe I'll code up an example.
Doing a search on "Genetic Algorithms" turns up a few really good nodes.
Helter
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.