Question: TASK5 JAVA LANG Page of 9 - 200W Task 5. Optional BONUS (+20 points) Write a program to solve the Vegetarians and Meat Eaters problem.
TASK5 JAVA LANG


Page of 9 - 200W Task 5. Optional BONUS (+20 points) Write a program to solve the "Vegetarians and Meat Eaters" problem. Three vegetarians and three hungry meal-eaters need to cross a river. Unfortunately, the boat only holds two people. If the meat-eaters outnumber the vegetarians on either bank, the vegetarians will be eaten! The computer must find a series of moves that gets all three vegetarians and all three meat-eaters across the river safely. I know you can solve the probleml Can the computer? You must give the computer some representation of the problem and the choices available. The computer must find the solution. You are given broad leeway on how to represent this problem. Recursion and backtracking (depth-first scarch) is one way to solve this Good luck! Example, with images thanks to https://www.learn good.com/kids-games/puzzle/boat.htm Start with three vegetarians and three meat-eaters on one side of the river. Put one V and one M on the boat to cross. This doesn't change the count: there's still three of each on the right side. Page of 9 - 200M + Have the boat cross Try again! There's now two Vs and three Ms on one side of the river, so the vegetarians get eaten. You can play the game htts://www.leemigad.com/kids-games/puzzle/bost htm d your device support Adobe Flash Hints: . When there's more meat-eaters than vegetarians on one side, the vegetarian(s) still get eaten. It doesn't matter if one meat-eater stays in the boat or not. At least one person has to take the boat across the river The base cases are: 4.1 3 vegetarians and 3 meat eaters on left side of river = success 4.2. 3 vegetarians and 3 meat eaters on right side of river = we're back at the start and have looped around, stop following this path 4.3. More meat eaters than vegetarians on left side of river - vegetarians get eaten More meat eaters than vegetarians on right side of river - vegetarians get eaten Output: I am not picky about output formatting, but the steps should be presented in a meaningful easy to follow way. Here is an example: Page
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
