Cody

Problem 2597. Alternative Scoring. Create an incremental spiral.

Solution 503237

Submitted on 20 Sep 2014 by Jan Orwat
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 = 1; assert(isequal(inv_spiral(x),y_correct))

2   Pass
%% x = 2; y_correct = [1 2 4 3]; assert(isequal(inv_spiral(x),y_correct))

3   Pass
%% x = 3; y_correct = [1 2 3 8 9 4 7 6 5]; assert(isequal(inv_spiral(x),y_correct))

4   Pass
%% x = 4; y_correct = [ 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7]; assert(isequal(inv_spiral(x),y_correct))

5   Pass
%% x = 5; y_correct = [1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9]; assert(isequal(inv_spiral(x),y_correct))

6   Pass
%% x = 6; y_correct = [1 2 3 4 5 6 20 21 22 23 24 7 19 32 33 34 25 8 18 31 36 35 26 9 17 30 29 28 27 10 16 15 14 13 12 11]; assert(isequal(inv_spiral(x),y_correct))

7   Pass
%% x = 7; y_correct = [1 2 3 4 5 6 7 24 25 26 27 28 29 8 23 40 41 42 43 30 9 22 39 48 49 44 31 10 21 38 47 46 45 32 11 20 37 36 35 34 33 12 19 18 17 16 15 14 13]; assert(isequal(inv_spiral(x),y_correct))

8   Pass
%% x = 8; y_correct = [1 2 3 4 5 6 7 8 28 29 30 31 32 33 34 9 27 48 49 50 51 52 35 10 26 47 60 61 62 53 36 11 25 46 59 64 63 54 37 12 24 45 58 57 56 55 38 13 23 44 43 42 41 40 39 14 22 21 20 19 18 17 16 15]; assert(isequal(inv_spiral(x),y_correct))

9   Pass
%% % size_old = feval(@evalin,'caller','score'); % % % ________SCORING_SYSTEM___________________ % all_nodes = mtree('inv_spiral.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('Size in proposed cody scoring is %i.\n',size); % if size==size_old&&size~=100 disp('Clean Code!'); % ... or dirty hack elseif size>size_old disp('Tried tricks?'); elseif size==100&&old_size==100 disp('You hacked it! or it is a nice coincidence'); elseif size<size_old disp('Something went wrong with scoring. (or you hacked it!)'); else disp('Master of Chaos.'); end % % This testsuite may be improved in the future. % %_________RESULT_____________________________

Size in standard cody scoring is 24. Size in proposed cody scoring is 26. Tried tricks?