Objective: To move all the vegetarians and meat eaters across the river.
Constraints: number of vegetarians need to be less than or equal to the number of meat eaters on either side of the river else vegetarians are killed.
State: configuration of vegetarians, meat eaters and boats on each side of the river.
Initial state: 3 vegetarians, 3 meat eaters and 1 boat on one side of the river bank.
Operator: Movement of boat with same set of operators for movement across the river.
Let us formulate the program using three distinctions represented by a simple vector <v,m,b>
We will denote the number of vegetarians and meat eaters depending on the number of their attendance on the side of the river bank for which we will estimate that particular state.
We will denote the position of boat as 0 or 1. If boat is on the right side then as 0 and if on the left side of the river then as 1.
Step 1: 3 vegetarians, 3 meat eaters are present at left side of the river bank. Path 1: <3,31>
Step 2: boat will take 1 vegetarian and 1 meat eater from left side of river to right side. Path2: <2,2,0>
Step 3: 1 vegetarian will row the boat from right end to meet other vegetarians and meat eaters at left side of the river. Path 3: <3,2,1>
Step 4: we can not exceed the number of meat eaters in respect to vegetarians because in that case vegetarians would be killed. So, two meat eat eaters would take the boat from left end to right end. At the left end, we will have 3 vegetarians awaiting. Path 4: <3,0,0>
Step 5: now, at the right end we have 3 meat eaters out of which 1 meat eater would row back to left end as the boat can not come on its own. Path 5: <3,1,1>
Step 6: 2 vegetarians would row for left end to right end, leaving 1 vegetarian and 1 meat eater at the left side of the river bank. Path 6: <1,1,0>
Step 7: when the boat reaches the right side of the river, we will have 2 vegetarians and 2 meat eaters. Path 7: < 2,2,1>
Step 8: now 1 meat eater would take boat to left side of the river, leaving 1 meat eater and 1 vegetarian at right side. Path 8: <0,2,0>
Step 9: now, 2 meat eaters would row from left side to right side of the river. Path 9: <0,1,0>
Step 10: when boat reaches right side of river, we observe there are 3 vegetarians and 2 meat eaters in total. Out of which, 1 meat eater would take the boat to left side of river to receive 1 meat eater awaiting. Path 10: <0,2,1>
Step 11: two meat eaters at left row to right end. Path 11: <0,0,1>
With, 3 vegetarians and 3 meat eaters on far side of river, status= success and path cost= 11.

import java.util.*;
class VM
{
int iV= 3, iM=3, i, fV=0, fM=0, status=0, select=0 ;
Boolean flag = false;
Void display ( char bpass 1, char bpass 2)
{
System.out.println ("\n\n\n");
For ( int i = 0; i<fV; i++)
System.out.println ("f-V");
For ( int i= 0; i< fM; i++)
System.out.println ("f-M");
if ( flag== false)
system.out.println ("to final" + bypass 1+ " "+bypass 2);
Else
System.out.println (bypass1+" "+ bypass 2+" to start");
For ( int i= 0; i<V; i++)
System.out.println ("i-M");
}
Boolean win ()
{
return ( fm== 3 && fv ==3) ? False: true;
}
Void solution ()
{
While (win ())
{
if (!flag)
{
switch ( select)
{
Case 1: display ( 'M',");
iM++;
Break;
Case 2: display ( 'm','v');
I'm++; iv++;
Break;
}
If (((iv-2)>=im && (fv+2)>= fm) || (iv-2)==0
{
iv=iv-2;
Select=1;
display ('v','v');
flag= true;
}
else if ((im-2)<iv && ((fv==0) || (fm+2)<=fv) || iv==0)
{
im= im-2;
Select=2;
Display ('M''M');
flag= true;
}
else if ((iM-)<=(iv-) && (fv++)>=fm++))
{
im= im-1;
iv= iv-1;
Select=3;
Display ('v','m'');
Flag=true;
}
}
else
{
Switch ( select)
{
Case1: display ('v','v');
fv= fv+2;
Break;
Case2: display ('m''m');
fm= fm+2;
Break;
Case3: display ('v','m');
fm=fm+1;
fv= fv+1;
Break;
}
if (win())
{
if (((fm>1 && fv==0) || (iv==0))
{
fm-;
select=1;
Display ('m',");
Flag=false;
}
else if ((I'm+2)>IV)
{
fm-; fv-;
select=2;
Display ( 'm','v');
Flag= false;
}
}
}
}
}
public static void main( string [] arrays)
{
VM= new VM ();
new.solution();
}
}
4. Comprehensive (20 points) Based on Goodrich Programming Projects 12.1. Write a program to solve the "Vegetarians...
Write a program to solve the “Vegetarians and Meat Eaters” problem. Three vegetarians and three hungry meat-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 problem! Can the computer? You must give the computer some...