CISC-280 Program Development Techniques
2. (10 Points) Exercise 3.3 on page 225 in the text.
3. (60 Points) State-Space Search: Missionaries and Cannibals
``Once upon a time, three missionaries were being guided through a
jungle by three cannibals to the nearest mission station. After some
time, they arrived at the left bank of a wide river, filled with deadly
snakes and fish. There was no way to cross the river without a boat.
Fortunately, they found a row boat with two oars after a short search.
Unfortunately, the boat was too small to carry all of them. It could
barely carry two people at a time. Worse, because of the river's width
there was no way to bring the boat back other than to row it back.
``Since the missionaries could not trust the cannibals they had to figure out a plan to get all six of them safely across the river. Luckily one of the missionaries had taken CISC-280 at UD and knew how to solve their problem. She devised a Scheme program to search a solution, implemented it on her laptop, ran it and used the computed solution to get them all safely to the other side of the river.''
What was the problem? The kind of cannibals in the story kill and eat missionaries as soon as there are more cannibals than missionaries at some place. Thus, our 280 graduate had to devise a plan that guaranteed that there were never any missionaries in the minority at either side of the river, or in the boat. However, the cannibals can be trusted to cooperate otherwise (they won't abandon any potential food, just as the missionaries won't abandon any potential converts).
Implement a Scheme program that finds a solution to the problem. Hint: solve this in steps, and make sure you have one step working before doing the next.
Hint: If the final program utilizes the first half-dozen functions, it will generate all states reachable with, say, seven crossings before it generates all those states reachable with eight crossings. Therefore you do not have to worry about cycles in solution attempts. QUESTION:Why are there cycles and why is this a problem for a computer program?
Hint: You might wish to write the program in three stages. Your first program should represent states in a manner that allows the program to find out whether a final state is reachable. This first program can return true if it is possible. Then, for the second edition, you must create state representations that include the list of crossings that got the group to this state. You can do this by simply altering your abstract data type with one more slot/element, and then update that as is appropriate. Of course, for the initial state this is just the empty list. For the third, final, and completely optional stage (that is, if you complete it, you will learn something but you won't get credit for it) eliminate all those states that represent solution attempts in which the same state would be reached (at least) twice. If you implement this third edition, you might wish to determine whether this measure saves time and how much time it saves.
You are welcome and encouraged to use Scheme's library functions as you see fit. This includes such operations as append, filter, map, etc. It will make your life easier.
Warning: The program can take about a minute to run on Strauss (or, if you mistakenly have an infinite loop, much, much, much longer......). I print a little "." each time I search one move deeper; you should find a solution within 12 moves. If you want to know how to do this the right way, take CISC-481 ! :-)
Partial Credit: If you do not get the program to work, state so at the top of your solution. Turn in your complete
work for each of the functions you finished instead. That is, show your
abstract data type definition, program examples, documentation,
function definition, and test cases. Alternatively, show the programs
or data definitions from which you abstract. We will give points
for partial solutions, if they show you made a systematic effort for
each sub-problem.