good chemistry is complicated,
and a little bit messy -LW
Solving riddles with Perlby Limbic~Region (Chancellor)
|on Sep 17, 2002 at 22:31 UTC||Need Help??|
I love problem solving. I love riddles. I love programming. These things are not unique, but I haven't found too many resources that depict methodologies on how to combine all three. Consider the following riddle from one of the Die Hard (I think) movies.
You have a 5 gallon bucket and a 3 gallon bucket with as much water as you need, but no other measuring devices. Fill the 5 gallon bucket with exactly 4 gallons of water. The solution is fairly simple:
To write this as a program, you need to be able to be able to create a decision tree. You need to be able to define a desired state. You need to be able to pipe the results of the decision back into the tree until you attain the desired state. A bonus would be to do this in the least number of iterations.
It is easy to describe these with words.
Of course there are some limitations on that last one
Is this type of programming practical with Perl? Would this program be too complex to generalize? If I were adept enough to write a program to solve the above riddle, it shouldn't be difficult to modify it to solve the following:
A farmer has a chicken, grain, and a fox. He needs to cross a river and can only take one item with him at a time. He can cross as many times as he needs to, but he can not leave the chicken and the fox together or the chicken and grain.
Solution available upon request. Better yet, write the program to solve it!
I have always been fascinated with AI and "stateful" programming, but always felt that languages like C were just too cumbersome to casually dabble with. Is Perl the same?
This post was for open discussion, I didn't expect someone to write the code. I am more interested in open discussion about this type of programming. With that said, I am VERY interested to see if anyone is capable of writing the code described above in the general sense