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 216040

Submitted on 11 Mar 2013 by Tim

Correct

372Size
This is the leading solution.
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 =
    22
T2 =
    70
L2 =
   57.2208