This solution is outdated. To rescore this solution, sign in.
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))
answer =
logical
1
|
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))
answer =
logical
0
|
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))
answer =
logical
0
|
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))
answer =
logical
0
|
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))
answer =
logical
0
|
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))
answer =
logical
1
|
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))
answer =
logical
1
|
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))
answer =
logical
0
|
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))
answer =
logical
1
|
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))
answer =
logical
1
|
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))
answer =
logical
0
|
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))
answer =
logical
0
|
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))
answer =
logical
0
|
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))
answer =
logical
1
|
624 Solvers
"Low : High - Low : High - Turn around " -- Create a subindices vector
320 Solvers
406 Solvers
583 Solvers
Rounding off numbers to n decimals
1050 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!