Cody

# Problem 1187. Knave in the middle attack

Solution 2649965

Submitted on 3 Jul 2020 by Rafael S.T. Vieira
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% Ask a Knight whether 4 is prime % (he will respond false; your function should respond true) A=true; X=@isprime; str='X(4)'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

X(4)

2   Pass
% Ask a Knave whether 4 is prime % (he will respond true; your function should respond false) A=false; X=@isprime; str='X(4)'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

X(4)

3   Pass
% Ask a Knight whether he is a Knight % (both Knights and Knaves would respond true and so should your function) A=true; X=@isprime; str='A==true'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

A==true

4   Pass
% Ask a Knave whether he is a Knight % (both Knights and Knaves would respond true and so should your function) A=false; X=@isprime; str='A==true'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

A==true

5   Pass
% Ask a Knight whether he would respond affirmatively to the question of whether he is a Knight % (a Knave would respond false to this same question, and so should your function) A=true; X=@isprime; str='F(''A==true'')'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

A==true

6   Pass
% Ask a Knave whether he would respond affirmatively to the question of whether he is a Knight % (a Knight would respond true to this same question, and so should your function) A=false; X=@isprime; str='F(''A==true'')'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

A==true

7   Pass
A=true; X=@isprime; str='diff(X(2:3))'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

diff(X(2:3))

8   Pass
A=false; X=@isprime; str='diff(X(2:3))'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

diff(X(2:3))

9   Pass
A=true; X=@isprime; str='A==X(6)'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

A==X(6)

10   Pass
A=false; X=@isprime; str='A==X(6)'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

A==X(6)

11   Pass
A=true; X=@isprime; str='A&any(X(1:3))'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

A&any(X(1:3))

12   Pass
A=false; X=@isprime; str='A&any(X(1:3))'; f0=inline('logical(interp1([0,1],[0,x],1))','x','A','X'); F=@(str)xor(~A,f0(eval(str),A,X)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

A&any(X(1:3))

13   Pass
A=true; 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)); clear A X; assert(isequal(AnswerGenerator(F,str),false))

X(3)

14   Pass
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)); clear A X; assert(isequal(AnswerGenerator(F,str),true))

X(3)
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://it.mathworks.com/matlabcentral/cody/problems/1187-knave-in-the-middle-attack/solutions/2649965", "fetch_time": 1597438400000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2020-34/segments/1596439739370.8/warc/CC-MAIN-20200814190500-20200814220500-00204.warc.gz", "warc_record_offset": 325886940, "warc_record_length": 16423, "token_count": 1443, "char_count": 3980, "score": 3.5, "int_score": 4, "crawl": "CC-MAIN-2020-34", "snapshot_type": "latest", "language": "en", "language_score": 0.45291629433631897, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00006-of-00064.parquet"}