Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you are visiting a forest in which every inhabitant is either a knight o

ID: 3581634 • Letter: S

Question

Suppose you are visiting a forest in which every inhabitant is either a knight or a knave. Knights always tell the truth and knaves always lie. In addition, some of the inhabitants are werewolves and have the annoying habit of sometimes turning into wolves at night and devouring people. A werewolf can be either a knight or a knave.

You are interviewing three inhabitants, A, B, and C. It is known that exactly one of them is a werewolf. They make the following statements:

A: I am a werewolf.

B: I am a werewolf.

C: At most one of us is a knight.

Formulate an integer program that will give a complete classification of A, B, and C (i.e. who/what each inhabitant is.) Clearly define (in words) all of your constraints

( I have started the IP as

X_{i}=left{egin{matrix}
1 & if knight \
0 & otherwise
end{matrix} ight.
i =1,2,3

W_{i}=left{egin{matrix}
1 & if werewolf \
0 & otherwise
end{matrix} ight.
i =1,2,3
1, 2 and 3 correspond to inhabitants A,B,S )

Explanation / Answer

main()
{
int A,B,C;
cout<<"1 is knight, 2 is knave , 3 is wolf";
cin>>A;
if (A==1)
{
cin>>B;
if(B==2)
c=3;

else
c=2;
}

if (A==2)
{
cin>>B;
if(B==1)
c=3;

else
c=1;
}

if (A==3)
{
cin>>B;
if(B==1)
c=2;

else
c=1;
}

else if(A==B||B==C||A==C)
{
break;
}

cout<<" "<<"1 is knight, 2 is knave , 3 is wolf";
cout<<"A::"<<A<<"B::"<<B<<"C::"<<C;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote