Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 215497

Submitted on 11 Mar 2013 by Alfonso Nieto-Castanon

Correct

793Size
Leading solution size is 372.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%% Test 1
x = [8.2 -6.9 3.2 -9.5 15.5 0.3 -4.9 7.6 4.5 -7.1 6.5 -7.5 5.6 -0.5] + i*[-4.4 3.8 7.7 -8 -1.9 16.5 2.3 6.8 6.6 -1.6 -1.2 5.5 -9.3 8.9];
tic;
y = TSP(x);
T1 = 1e4*toc;
L1 = sum(abs(diff(y)));
S = calculateSize('tsp.m')
assert(isequal(sort(y),sort(x)))
% Test 2
x = 10*sin(primes(200))+10i*cos(primes(200));
tic;
y = TSP(x);
T2 = 1e6*toc
L2 = sum(abs(diff(y)))
assert(isequal(sort(y),sort(x)))
% Test 3
x = [75.5 5.43 94.73 3.89 .37 42.38 -8.5 36.72 .54 .02 83.27 47];
tic;
y = TSP(x(randperm(12)));
T3 = 1e5*toc;
L3 = sum(abs(diff(y)));
assert(isequal(sort(y),sort(x)))
assignin('caller','score',round(S +T1+L1 +T2+L2 +T3+L3));
S =
    24
T2 =
   115
L2 =
   60.5192