Cody

Solution 1699607

Submitted on 26 Dec 2018 by Martin C.
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
x = 1; y_correct = false; assert(isequal(isevil(x),y_correct))

c = 0 c = 1 n = 0 tf = logical 0

2   Pass
x = 3; y_correct = true; assert(isequal(isevil(x),y_correct))

c = 0 c = 1 n = 1 c = 2 n = 0 tf = logical 1

3   Pass
x = [18, 20, 23, 24, 27, 45, 46, 48, 96, 99, 123,]; y_correct = true; assert(isequal(all(arrayfun(@isevil,x)),y_correct))

c = 0 c = 0 n = 9 c = 1 n = 4 c = 1 n = 2 c = 1 n = 1 c = 2 n = 0 tf = logical 1 c = 0 c = 0 n = 10 c = 0 n = 5 c = 1 n = 2 c = 1 n = 1 c = 2 n = 0 tf = logical 1 c = 0 c = 1 n = 11 c = 2 n = 5 c = 3 n = 2 c = 3 n = 1 c = 4 n = 0 tf = logical 1 c = 0 c = 0 n = 12 c = 0 n = 6 c = 0 n = 3 c = 1 n = 1 c = 2 n = 0 tf = logical 1 c = 0 c = 1 n = 13 c = 2 n = 6 c = 2 n = 3 c = 3 n = 1 c = 4 n = 0 tf = logical 1 c = 0 c = 1 n = 22 c = 1 n = 11 c = 2 n = 5 c = 3 n = 2 c = 3 n = 1 c = 4 n = 0 tf = logical 1 c = 0 c = 0 n = 23 c = 1 n = 11 c = 2 n = 5 c = 3 n = 2 c = 3 n = 1 c = 4 n = 0 tf = logical 1 c = 0 c = 0 n = 24 c = 0 n = 12 c = 0 n = 6 c = 0 n = 3 c = 1 n = 1 c = 2 n = 0 tf = logical 1 c = 0 c = 0 n = 48 c = 0 n = 24 c = 0 n = 12 c = 0 n = 6 c = 0 n = 3 c = 1 n = 1 c = 2 n = 0 tf = logical 1 c = 0 c = 1 n = 49 c = 2 n = 24 c = 2 n = 12 c = 2 n = 6 c = 2 n = 3 c = 3 n = 1 c = 4 n = 0 tf = logical 1 c = 0 c = 1 n = 61 c = 2 n = 30 c = 2 n = 15 c = 3 n = 7 c = 4 n = 3 c = 5 n = 1 c = 6 n = 0 tf = logical 1

4   Pass
x = [14, 16, 19, 37, 38, 55, 56, 59, 62, 79, 82, 91, 93, 94, 97, 98, 117, 118, 121]; y_correct = false; assert(isequal(any(arrayfun(@isevil,x)),y_correct))

c = 0 c = 0 n = 7 c = 1 n = 3 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 0 n = 8 c = 0 n = 4 c = 0 n = 2 c = 0 n = 1 c = 1 n = 0 tf = logical 0 c = 0 c = 1 n = 9 c = 2 n = 4 c = 2 n = 2 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 1 n = 18 c = 1 n = 9 c = 2 n = 4 c = 2 n = 2 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 0 n = 19 c = 1 n = 9 c = 2 n = 4 c = 2 n = 2 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 1 n = 27 c = 2 n = 13 c = 3 n = 6 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 0 n = 28 c = 0 n = 14 c = 0 n = 7 c = 1 n = 3 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 1 n = 29 c = 2 n = 14 c = 2 n = 7 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 0 n = 31 c = 1 n = 15 c = 2 n = 7 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 1 n = 39 c = 2 n = 19 c = 3 n = 9 c = 4 n = 4 c = 4 n = 2 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 0 n = 41 c = 1 n = 20 c = 1 n = 10 c = 1 n = 5 c = 2 n = 2 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 1 n = 45 c = 2 n = 22 c = 2 n = 11 c = 3 n = 5 c = 4 n = 2 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 1 n = 46 c = 1 n = 23 c = 2 n = 11 c = 3 n = 5 c = 4 n = 2 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 0 n = 47 c = 1 n = 23 c = 2 n = 11 c = 3 n = 5 c = 4 n = 2 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 1 n = 48 c = 1 n = 24 c = 1 n = 12 c = 1 n = 6 c = 1 n = 3 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 0 n = 49 c = 1 n = 24 c = 1 n = 12 c = 1 n = 6 c = 1 n = 3 c = 2 n = 1 c = 3 n = 0 tf = logical 0 c = 0 c = 1 n = 58 c = 1 n = 29 c = 2 n = 14 c = 2 n = 7 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 0 n = 59 c = 1 n = 29 c = 2 n = 14 c = 2 n = 7 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0 c = 0 c = 1 n = 60 c = 1 n = 30 c = 1 n = 15 c = 2 n = 7 c = 3 n = 3 c = 4 n = 1 c = 5 n = 0 tf = logical 0

5   Pass
x = 2^randi([5 10])+1; y_correct = true; assert(isequal(isevil(x),y_correct))

c = 0 c = 1 n = 256 c = 1 n = 128 c = 1 n = 64 c = 1 n = 32 c = 1 n = 16 c = 1 n = 8 c = 1 n = 4 c = 1 n = 2 c = 1 n = 1 c = 2 n = 0 tf = logical 1

6   Pass
% more test cases may be introduced

7   Pass
% DISABLED % ________'FAIR'_SCORING_SYSTEM______________ % % This section scores for usage of ans % and strings, which are common methods % to reduce cody size of solution. % Here, strings are threated like vectors. % Please do not hack it, as this problem % is not mentioned to be a hacking problem. % try % disable: assert(false) % size_old = feval(@evalin,'caller','score'); % all_nodes = mtree('isevil.m','-file'); str_nodes = mtfind(all_nodes,'Kind','STRING'); eq_nodes = mtfind(all_nodes,'Kind','EQUALS'); print_nodes = mtfind(all_nodes,'Kind','PRINT'); expr_nodes = mtfind(all_nodes,'Kind','EXPR'); % size = count(all_nodes) ... +sum(str_nodes.nodesize-1) ... +2*(count(expr_nodes) ... +count(print_nodes) ... -count(eq_nodes)); % feval(@assignin,'caller','score',size); % fprintf('Size in standard cody scoring is %i.\n',size_old); fprintf('Here it is %i.\n',size); end % %_________RESULT_____________________________

Suggested Problems

More from this Author47