Cody

# Problem 2733. Evil Number

Solution 2204421

Submitted on 10 Apr 2020 by Michael Jarboe
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))

N = '1' A = logical 1 a = 1 tf = logical 0

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

N = '11' A = 1×2 logical array 1 1 a = 2 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))

N = '10010' A = 1×5 logical array 1 0 0 1 0 a = 2 tf = logical 1 N = '10100' A = 1×5 logical array 1 0 1 0 0 a = 2 tf = logical 1 N = '10111' A = 1×5 logical array 1 0 1 1 1 a = 4 tf = logical 1 N = '11000' A = 1×5 logical array 1 1 0 0 0 a = 2 tf = logical 1 N = '11011' A = 1×5 logical array 1 1 0 1 1 a = 4 tf = logical 1 N = '101101' A = 1×6 logical array 1 0 1 1 0 1 a = 4 tf = logical 1 N = '101110' A = 1×6 logical array 1 0 1 1 1 0 a = 4 tf = logical 1 N = '110000' A = 1×6 logical array 1 1 0 0 0 0 a = 2 tf = logical 1 N = '1100000' A = 1×7 logical array 1 1 0 0 0 0 0 a = 2 tf = logical 1 N = '1100011' A = 1×7 logical array 1 1 0 0 0 1 1 a = 4 tf = logical 1 N = '1111011' A = 1×7 logical array 1 1 1 1 0 1 1 a = 6 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))

N = '1110' A = 1×4 logical array 1 1 1 0 a = 3 tf = logical 0 N = '10000' A = 1×5 logical array 1 0 0 0 0 a = 1 tf = logical 0 N = '10011' A = 1×5 logical array 1 0 0 1 1 a = 3 tf = logical 0 N = '100101' A = 1×6 logical array 1 0 0 1 0 1 a = 3 tf = logical 0 N = '100110' A = 1×6 logical array 1 0 0 1 1 0 a = 3 tf = logical 0 N = '110111' A = 1×6 logical array 1 1 0 1 1 1 a = 5 tf = logical 0 N = '111000' A = 1×6 logical array 1 1 1 0 0 0 a = 3 tf = logical 0 N = '111011' A = 1×6 logical array 1 1 1 0 1 1 a = 5 tf = logical 0 N = '111110' A = 1×6 logical array 1 1 1 1 1 0 a = 5 tf = logical 0 N = '1001111' A = 1×7 logical array 1 0 0 1 1 1 1 a = 5 tf = logical 0 N = '1010010' A = 1×7 logical array 1 0 1 0 0 1 0 a = 3 tf = logical 0 N = '1011011' A = 1×7 logical array 1 0 1 1 0 1 1 a = 5 tf = logical 0 N = '1011101' A = 1×7 logical array 1 0 1 1 1 0 1 a = 5 tf = logical 0 N = '1011110' A = 1×7 logical array 1 0 1 1 1 1 0 a = 5 tf = logical 0 N = '1100001' A = 1×7 logical array 1 1 0 0 0 0 1 a = 3 tf = logical 0 N = '1100010' A = 1×7 logical array 1 1 0 0 0 1 0 a = 3 tf = logical 0 N = '1110101' A = 1×7 logical array 1 1 1 0 1 0 1 a = 5 tf = logical 0 N = '1110110' A = 1×7 logical array 1 1 1 0 1 1 0 a = 5 tf = logical 0 N = '1111001' A = 1×7 logical array 1 1 1 1 0 0 1 a = 5 tf = logical 0

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

N = '1000001' A = 1×7 logical array 1 0 0 0 0 0 1 a = 2 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_____________________________

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!