This week's assignment is a single project. You receive 12pts for completing the project. For partial credit, see below.
``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 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 Comp 210 at Rice University and knew how to solve their problem. He 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 Comp 210 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.
Hints:If the final program utilizes the others, 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. Why are there cycles and why is this a problem for a computer program?
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 the group to this state. Of course, for the initial state this is just the empty list. The third and final stage is completely optional. Here you might consider eliminating states from the list that represent cyclic solutions attempts. If you implement this third edition, you might wish to measure 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, foldl,
foldr, map,
etc. It will make your life
easier.
Product: Your program must be annotated with
Warning: The program can take about a minute to run on the Ryon Sparcs (or, if you mistakenly have an infinite loop, much, much longer).
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 data definition, contract, program examples, template, function definition, and test cases. Alternatively, show the programs or data definitions from which you abstract. We will give up to nine points for partial solutions, if they show you made a systematic effort for each sub-problem.