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 216508

Submitted on 12 Mar 2013 by Richard Zapor

Correct

1090Size
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));
ans =
  Columns 1 through 5
  -4.9000 + 2.3000i   6.5000 - 1.2000i  -7.1000 - 1.6000i  -6.9000 + 3.8000i   4.5000 + 6.6000i
  Columns 6 through 10
   3.2000 + 7.7000i  -0.5000 + 8.9000i  -7.5000 + 5.5000i   8.2000 - 4.4000i   7.6000 + 6.8000i
  Columns 11 through 14
   5.6000 - 9.3000i  -9.5000 - 8.0000i  15.5000 - 1.9000i   0.3000 +16.5000i
S =
    10
ans =
  Columns 1 through 5
   9.6836 + 2.4954i  -9.9999 + 0.0443i   0.7072 - 9.9750i  -0.7955 + 9.9683i  -0.9718 + 9.9527i
  Columns 6 through 10
   1.2357 - 9.9234i   1.4112 - 9.8999i   1.4988 + 9.8870i  -1.5862 - 9.8734i   1.8478 + 9.8278i
  Columns 11 through 15
   2.0215 + 9.7935i  -9.7846 - 2.0645i  -2.1081 - 9.7753i  -9.7465 - 2.2374i   9.7263 + 2.3236i
  Columns 16 through 20
  -9.6612 - 2.5810i  -9.6140 - 2.7516i  -9.5892 + 2.8366i   9.5105 - 3.0902i  -9.4251 + 3.3417i
  Columns 21 through 25
  -9.3645 + 3.5080i  -3.5491 + 9.3490i   3.7961 - 9.2515i   3.9593 - 9.1828i  -4.0404 + 9.1474i
  Columns 26 through 30
   9.0930 - 4.1615i   4.2017 + 9.0745i  -4.4411 - 8.9597i   4.5203 + 8.9200i  -8.8180 - 4.7163i
  Columns 31 through 35
  -4.7555 - 8.7969i   8.6007 + 5.1018i  -8.5552 - 5.1777i  -8.4622 - 5.3283i  -8.3177 + 5.5511i
  Columns 36 through 40
   8.1674 - 5.7700i  -8.1160 + 5.8421i   5.9491 - 8.0379i   7.9581 - 6.0555i   6.2299 - 7.8223i
  Columns 41 through 45
   6.3674 - 7.7108i  -6.4354 + 7.6541i   6.5699 + 7.5390i  -6.6363 - 7.4806i  -6.7677 - 7.3619i
  Column 46
   6.9608 + 7.1796i
T2 =
   192
L2 =
  593.8962
ans =
  Columns 1 through 10
   -8.5000    0.0200    0.3700    0.5400    3.8900    5.4300   36.7200   42.3800   47.0000   75.5000
  Columns 11 through 12
   83.2700   94.7300