This is a Matlab adaptation of the Knights and Knaves logical puzzles.
You are in an island where all inhabitants are either Knights, who always tell the truth, or Knaves, who always lie. The island inhabitants can always tell Knights and Knaves apart by their appearance, but to you, as an outsider, they look exactly the same.
Previous problem in this series: Knights and Knaves (part 2)
That mob of islanders turned out to be a friendly bunch after all, and with their help you reach the castle in no time. The doors to the castle are guarded by a sentinel who will only let you in if you answer correctly the day's password. Fortunately islanders are not particularly security conscious and the guard is happy to answer as many questions as you see fit. What is today's password?
You are given a function handle QUESTION that allows you to query the guard (either a Knight or a Knave, you do not know which). The function y=QUESTION(str) takes a string str as input (the 'question'), and returns a logical value (the yes/no 'answer' the guard would give to this question). Valid questions are any valid matlab syntax. The guard has access to the following variables (his pool of 'knowledge'):
You may query the guard by evaluating the function QUESTION. For example x=QUESTION('KNIGHT==true') asks the guard whether he is a Knight.
Your function should return the correct password.