Problem 1187. Knave in the middle attack
 A: Islander's type. A is a logical variable: true for a Knight, false for a Knave
 X: A secret formula only islanders know. An unknown function on positive integer values that when evaluated returns a logical value (e.g. x>1).
 F: Introspection. F is the handle associated with this islander's answers, so he knows himself what he would respond to some hypothetical question
Solution Stats
Problem Comments

5 Comments
Broken test suite? The handle wont work in some cases
Yes, it seems that test suit is wrong. cases 13 e 14 won't work.
For instance from case 13:
A=false; X=@(x)rem(x,2); str='F(''F(''''X(3)'''')'')';
f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X');
F=@(str)xor(~A,f0(eval(str),A,X));
if I execute F(str) inside my function AnswerGenerator it complains...
Error using eval
Unrecognized function or variable 'F'.
It seems the syntax is wrong. So we cannot know what the answer would be from the knight or the knave (I'm trying to fix the string input).
So I was able to fix the strings (str) manually using replace. Previous solutions won't work, so I guess the test cases were changed and broken. Please ignore my solution if this is fixed later on (it's only right for now, fixing it and evaluating it manually is a pain). I will resubmit a proper solution when it is fixed and I see it fixed.
Problematic test cases have been commented out. Hopefully, @Alfonso will get around to fixing this.
thanks for the heads up and temporal fix. I am still looking into this, it seems that the issue was probably a change in memorymanagement affecting function handles in some of the more recent Matlab releases, and I should probably just change the way I implement the Knight/Knave answer function to explicitly allow selfreferences...
Solution Comments
Show commentsProblem Recent Solvers15
Suggested Problems

Test if a Number is a Palindrome without using any String Operations
223 Solvers

Find the maximum number of decimal places in a set of numbers
2498 Solvers

352 Solvers

Given a matrix, swap the 2nd & 3rd columns
984 Solvers

Big numbers, least significant digits
83 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!