Manhattan Tourist Problem Perl

I solved the  Manhattan Tourist Problem or called Travelling salesman problem in Perl.At first I go from left to right and then form up to down but the best way is to look if its better to go right or down.The last solution is to make a brute force for the first 32 steps but this very very slow, for another brute fore example look at : Brute Force with Perl.

Generate data:

Example Data:

 

Output looks like this:

I marked the right number in HTML to see the way ….

From left to right:
3.34 3.61 0.19 9.43 5.95 9.89 3.19 3.78 8.84 2.36 9.69 2.25 4.60 8.41 4.54 8.07 2.00 8.90 8.07 2.51 7.60
9.49 4.81 3.77 3.12 2.39 7.95 2.93 5.31 9.81 6.77 9.96 6.90 9.04 8.79 5.66 9.33 1.42 1.28 2.48 7.93 1.69
1.51 6.42 7.55 5.98 2.70 0.04 2.20 5.36 5.09 5.38 5.69 1.97 0.54 2.81 5.43 8.66 3.20 4.07 7.87 1.96 1.77
3.73 9.47 7.81 4.92 5.07 9.36 0.25 7.13 1.59 1.84 0.69 7.21 3.28 4.94 0.66 4.64 3.72 2.29 0.91 6.04 5.68
5.38 3.06 5.33 5.30 2.33 8.06 9.57 9.22 2.66 2.86 9.54 1.60 0.27 8.50 9.49 5.18 1.73 1.43 6.71 9.57 4.75
2.65 5.82 1.62 3.15 7.12 8.08 4.89 4.49 9.23 6.65 5.02 6.05 5.96 9.96 1.28 0.29 3.49 6.59 6.04 5.38 7.97
4.07 9.46 8.46 6.47 6.72 4.28 0.99 0.70 3.13 4.34 1.34 5.31 4.52 1.68 8.37 3.52 2.26 9.85 1.30 9.57 4.43
4.58 2.95 7.82 0.87 3.36 9.91 7.32 8.21 9.86 9.87 5.85 5.59 2.57 2.57 5.43 9.90 1.58 1.68 7.75 2.09 0.99
1.87 2.86 1.63 0.52 4.34 0.25 2.50 9.86 0.47 1.96 5.28 1.03 0.62 2.09 5.50 8.10 4.93 2.80 9.75 5.55 6.19
1.67 8.35 4.13 7.43 7.64 5.22 0.22 0.26 8.89 3.42 8.01 1.33 7.86 3.77 1.57 7.09 9.51 7.21 5.25 0.31 3.71
0.72 7.86 9.56 2.73 6.34 8.33 7.60 7.91 1.64 5.91 8.30 4.05 3.14 6.21 3.91 8.01 8.51 8.15 2.77 4.09 3.73
7.06 7.47 8.36 2.35 3.21 1.82 0.61 2.27 4.27 0.08 2.31 0.49 7.10 1.32 5.40 8.47 1.46 5.61 6.81 4.78 1.75
6.34 9.92 9.71 7.83 6.29 6.92 0.15 1.89 3.51 3.48 5.29 1.08 2.77 4.93 4.26 1.52 6.80 5.69 7.75 1.67 0.64
9.51 5.83 6.28 6.71 0.51 5.89 8.78 5.42 3.81 2.89 8.52 8.46 2.64 4.13 5.25 2.42 6.91 2.72 7.99 9.32 8.29
5.90 5.95 5.33 2.79 1.84 2.06 9.38 1.39 2.09 2.03 0.22 1.78 8.08 5.83 2.64 3.19 1.37 0.76 7.02 4.88 6.39
4.56 7.22 8.19 5.93 9.52 1.45 8.04 6.99 7.60 4.82 1.13 5.03 0.68 3.81 3.96 7.15 5.80 9.06 0.96 8.59 2.77
0.48 1.89 7.96 1.80 1.95 5.24 4.98 3.21 5.16 1.70 3.19 5.92 5.53 4.62 0.26 6.29 4.32 7.15 0.66 8.64 3.42
0.69 1.02 0.92 1.20 4.49 5.42 4.17 2.58 2.18 9.32 1.92 7.71 7.02 0.22 8.92 1.80 3.87 6.26 9.61 2.00 3.27
1.12 2.83 7.25 9.60 9.80 2.75 2.00 5.87 5.20 0.97 9.16 5.93 4.38 1.15 2.59 1.63 2.78 8.13 6.12 5.85 1.44
5.58 4.25 8.00 8.86 9.10 5.27 2.49 4.97 4.25 6.24 9.98 7.23 2.73 7.25 1.19 1.67 6.91 6.30 2.38 5.72 9.32
4.40 4.66 2.37 0.17 1.92 6.17 3.31 6.44 9.64 0.03 0.78 0.17 5.03 4.82 7.94 0.10 1.32 8.29 5.57 1.39 3.66

From up to down:
3.34 3.61 0.19 9.43 5.95 9.89 3.19 3.78 8.84 2.36 9.69 2.25 4.60 8.41 4.54 8.07 2.00 8.90 8.07 2.51 7.60
9.49 4.81 3.77 3.12 2.39 7.95 2.93 5.31 9.81 6.77 9.96 6.90 9.04 8.79 5.66 9.33 1.42 1.28 2.48 7.93 1.69
1.51 6.42 7.55 5.98 2.70 0.04 2.20 5.36 5.09 5.38 5.69 1.97 0.54 2.81 5.43 8.66 3.20 4.07 7.87 1.96 1.77
3.73 9.47 7.81 4.92 5.07 9.36 0.25 7.13 1.59 1.84 0.69 7.21 3.28 4.94 0.66 4.64 3.72 2.29 0.91 6.04 5.68
5.38 3.06 5.33 5.30 2.33 8.06 9.57 9.22 2.66 2.86 9.54 1.60 0.27 8.50 9.49 5.18 1.73 1.43 6.71 9.57 4.75
2.65 5.82 1.62 3.15 7.12 8.08 4.89 4.49 9.23 6.65 5.02 6.05 5.96 9.96 1.28 0.29 3.49 6.59 6.04 5.38 7.97
4.07 9.46 8.46 6.47 6.72 4.28 0.99 0.70 3.13 4.34 1.34 5.31 4.52 1.68 8.37 3.52 2.26 9.85 1.30 9.57 4.43
4.58 2.95 7.82 0.87 3.36 9.91 7.32 8.21 9.86 9.87 5.85 5.59 2.57 2.57 5.43 9.90 1.58 1.68 7.75 2.09 0.99
1.87 2.86 1.63 0.52 4.34 0.25 2.50 9.86 0.47 1.96 5.28 1.03 0.62 2.09 5.50 8.10 4.93 2.80 9.75 5.55 6.19
1.67 8.35 4.13 7.43 7.64 5.22 0.22 0.26 8.89 3.42 8.01 1.33 7.86 3.77 1.57 7.09 9.51 7.21 5.25 0.31 3.71
0.72 7.86 9.56 2.73 6.34 8.33 7.60 7.91 1.64 5.91 8.30 4.05 3.14 6.21 3.91 8.01 8.51 8.15 2.77 4.09 3.73
7.06 7.47 8.36 2.35 3.21 1.82 0.61 2.27 4.27 0.08 2.31 0.49 7.10 1.32 5.40 8.47 1.46 5.61 6.81 4.78 1.75
6.34 9.92 9.71 7.83 6.29 6.92 0.15 1.89 3.51 3.48 5.29 1.08 2.77 4.93 4.26 1.52 6.80 5.69 7.75 1.67 0.64
9.51 5.83 6.28 6.71 0.51 5.89 8.78 5.42 3.81 2.89 8.52 8.46 2.64 4.13 5.25 2.42 6.91 2.72 7.99 9.32 8.29
5.90 5.95 5.33 2.79 1.84 2.06 9.38 1.39 2.09 2.03 0.22 1.78 8.08 5.83 2.64 3.19 1.37 0.76 7.02 4.88 6.39
4.56 7.22 8.19 5.93 9.52 1.45 8.04 6.99 7.60 4.82 1.13 5.03 0.68 3.81 3.96 7.15 5.80 9.06 0.96 8.59 2.77
0.48 1.89 7.96 1.80 1.95 5.24 4.98 3.21 5.16 1.70 3.19 5.92 5.53 4.62 0.26 6.29 4.32 7.15 0.66 8.64 3.42
0.69 1.02 0.92 1.20 4.49 5.42 4.17 2.58 2.18 9.32 1.92 7.71 7.02 0.22 8.92 1.80 3.87 6.26 9.61 2.00 3.27
1.12 2.83 7.25 9.60 9.80 2.75 2.00 5.87 5.20 0.97 9.16 5.93 4.38 1.15 2.59 1.63 2.78 8.13 6.12 5.85 1.44
5.58 4.25 8.00 8.86 9.10 5.27 2.49 4.97 4.25 6.24 9.98 7.23 2.73 7.25 1.19 1.67 6.91 6.30 2.38 5.72 9.32
4.40 4.66 2.37 0.17 1.92 6.17 3.31 6.44 9.64 0.03 0.78 0.17 5.03 4.82 7.94 0.10 1.32 8.29 5.57 1.39 3.66

Find the right way, check if you should go right or down:
3.34 3.61 0.19 9.43 5.95 9.89 3.19 3.78 8.84 2.36 9.69 2.25 4.60 8.41 4.54 8.07 2.00 8.90 8.07 2.51 7.60
9.49 4.81 3.77 3.12 2.39 7.95 2.93 5.31 9.81 6.77 9.96 6.90 9.04 8.79 5.66 9.33 1.42 1.28 2.48 7.93 1.69
1.51 6.42 7.55 5.98 2.70 0.04 2.20 5.36 5.09 5.38 5.69 1.97 0.54 2.81 5.43 8.66 3.20 4.07 7.87 1.96 1.77
3.73 9.47 7.81 4.92 5.07 9.36 0.25 7.13 1.59 1.84 0.69 7.21 3.28 4.94 0.66 4.64 3.72 2.29 0.91 6.04 5.68
5.38 3.06 5.33 5.30 2.33 8.06 9.57 9.22 2.66 2.86 9.54 1.60 0.27 8.50 9.49 5.18 1.73 1.43 6.71 9.57 4.75
2.65 5.82 1.62 3.15 7.12 8.08 4.89 4.49 9.23 6.65 5.02 6.05 5.96 9.96 1.28 0.29 3.49 6.59 6.04 5.38 7.97
4.07 9.46 8.46 6.47 6.72 4.28 0.99 0.70 3.13 4.34 1.34 5.31 4.52 1.68 8.37 3.52 2.26 9.85 1.30 9.57 4.43
4.58 2.95 7.82 0.87 3.36 9.91 7.32 8.21 9.86 9.87 5.85 5.59 2.57 2.57 5.43 9.90 1.58 1.68 7.75 2.09 0.99
1.87 2.86 1.63 0.52 4.34 0.25 2.50 9.86 0.47 1.96 5.28 1.03 0.62 2.09 5.50 8.10 4.93 2.80 9.75 5.55 6.19
1.67 8.35 4.13 7.43 7.64 5.22 0.22 0.26 8.89 3.42 8.01 1.33 7.86 3.77 1.57 7.09 9.51 7.21 5.25 0.31 3.71
0.72 7.86 9.56 2.73 6.34 8.33 7.60 7.91 1.64 5.91 8.30 4.05 3.14 6.21 3.91 8.01 8.51 8.15 2.77 4.09 3.73
7.06 7.47 8.36 2.35 3.21 1.82 0.61 2.27 4.27 0.08 2.31 0.49 7.10 1.32 5.40 8.47 1.46 5.61 6.81 4.78 1.75
6.34 9.92 9.71 7.83 6.29 6.92 0.15 1.89 3.51 3.48 5.29 1.08 2.77 4.93 4.26 1.52 6.80 5.69 7.75 1.67 0.64
9.51 5.83 6.28 6.71 0.51 5.89 8.78 5.42 3.81 2.89 8.52 8.46 2.64 4.13 5.25 2.42 6.91 2.72 7.99 9.32 8.29
5.90 5.95 5.33 2.79 1.84 2.06 9.38 1.39 2.09 2.03 0.22 1.78 8.08 5.83 2.64 3.19 1.37 0.76 7.02 4.88 6.39
4.56 7.22 8.19 5.93 9.52 1.45 8.04 6.99 7.60 4.82 1.13 5.03 0.68 3.81 3.96 7.15 5.80 9.06 0.96 8.59 2.77
0.48 1.89 7.96 1.80 1.95 5.24 4.98 3.21 5.16 1.70 3.19 5.92 5.53 4.62 0.26 6.29 4.32 7.15 0.66 8.64 3.42
0.69 1.02 0.92 1.20 4.49 5.42 4.17 2.58 2.18 9.32 1.92 7.71 7.02 0.22 8.92 1.80 3.87 6.26 9.61 2.00 3.27
1.12 2.83 7.25 9.60 9.80 2.75 2.00 5.87 5.20 0.97 9.16 5.93 4.38 1.15 2.59 1.63 2.78 8.13 6.12 5.85 1.44
5.58 4.25 8.00 8.86 9.10 5.27 2.49 4.97 4.25 6.24 9.98 7.23 2.73 7.25 1.19 1.67 6.91 6.30 2.38 5.72 9.32
4.40 4.66 2.37 0.17 1.92 6.17 3.31 6.44 9.64 0.03 0.78 0.17 5.03 4.82 7.94 0.10 1.32 8.29 5.57 1.39 3.66

Brute Force with 32 steps, I get the result after some hours but its not finish:
3.34 3.61 0.19 9.43 5.95 9.89 3.19 3.78 8.84 2.36 9.69 2.25 4.60 8.41 4.54 8.07 2.00 8.90 8.07 2.51 7.60
9.49 4.81 3.77 3.12 2.39 7.95 2.93 5.31 9.81 6.77 9.96 6.90 9.04 8.79 5.66 9.33 1.42 1.28 2.48 7.93 1.69
1.51 6.42 7.55 5.98 2.70 0.04 2.20 5.36 5.09 5.38 5.69 1.97 0.54 2.81 5.43 8.66 3.20 4.07 7.87 1.96 1.77
3.73 9.47 7.81 4.92 5.07 9.36 0.25 7.13 1.59 1.84 0.69 7.21 3.28 4.94 0.66 4.64 3.72 2.29 0.91 6.04 5.68
5.38 3.06 5.33 5.30 2.33 8.06 9.57 9.22 2.66 2.86 9.54 1.60 0.27 8.50 9.49 5.18 1.73 1.43 6.71 9.57 4.75
2.65 5.82 1.62 3.15 7.12 8.08 4.89 4.49 9.23 6.65 5.02 6.05 5.96 9.96 1.28 0.29 3.49 6.59 6.04 5.38 7.97
4.07 9.46 8.46 6.47 6.72 4.28 0.99 0.70 3.13 4.34 1.34 5.31 4.52 1.68 8.37 3.52 2.26 9.85 1.30 9.57 4.43
4.58 2.95 7.82 0.87 3.36 9.91 7.32 8.21 9.86 9.87 5.85 5.59 2.57 2.57 5.43 9.90 1.58 1.68 7.75 2.09 0.99
1.87 2.86 1.63 0.52 4.34 0.25 2.50 9.86 0.47 1.96 5.28 1.03 0.62 2.09 5.50 8.10 4.93 2.80 9.75 5.55 6.19
1.67 8.35 4.13 7.43 7.64 5.22 0.22 0.26 8.89 3.42 8.01 1.33 7.86 3.77 1.57 7.09 9.51 7.21 5.25 0.31 3.71
0.72 7.86 9.56 2.73 6.34 8.33 7.60 7.91 1.64 5.91 8.30 4.05 3.14 6.21 3.91 8.01 8.51 8.15 2.77 4.09 3.73
7.06 7.47 8.36 2.35 3.21 1.82 0.61 2.27 4.27 0.08 2.31 0.49 7.10 1.32 5.40 8.47 1.46 5.61 6.81 4.78 1.75
6.34 9.92 9.71 7.83 6.29 6.92 0.15 1.89 3.51 3.48 5.29 1.08 2.77 4.93 4.26 1.52 6.80 5.69 7.75 1.67 0.64
9.51 5.83 6.28 6.71 0.51 5.89 8.78 5.42 3.81 2.89 8.52 8.46 2.64 4.13 5.25 2.42 6.91 2.72 7.99 9.32 8.29
5.90 5.95 5.33 2.79 1.84 2.06 9.38 1.39 2.09 2.03 0.22 1.78 8.08 5.83 2.64 3.19 1.37 0.76 7.02 4.88 6.39
4.56 7.22 8.19 5.93 9.52 1.45 8.04 6.99 7.60 4.82 1.13 5.03 0.68 3.81 3.96 7.15 5.80 9.06 0.96 8.59 2.77
0.48 1.89 7.96 1.80 1.95 5.24 4.98 3.21 5.16 1.70 3.19 5.92 5.53 4.62 0.26 6.29 4.32 7.15 0.66 8.64 3.42
0.69 1.02 0.92 1.20 4.49 5.42 4.17 2.58 2.18 9.32 1.92 7.71 7.02 0.22 8.92 1.80 3.87 6.26 9.61 2.00 3.27
1.12 2.83 7.25 9.60 9.80 2.75 2.00 5.87 5.20 0.97 9.16 5.93 4.38 1.15 2.59 1.63 2.78 8.13 6.12 5.85 1.44
5.58 4.25 8.00 8.86 9.10 5.27 2.49 4.97 4.25 6.24 9.98 7.23 2.73 7.25 1.19 1.67 6.91 6.30 2.38 5.72 9.32
4.40 4.66 2.37 0.17 1.92 6.17 3.31 6.44 9.64 0.03 0.78 0.17 5.03 4.82 7.94 0.10 1.32 8.29 5.57 1.39 3.66

2 thoughts on “Manhattan Tourist Problem Perl”

  1. Awesome blog! Do you have any suggestions for aspiring writers?
    I’m planning to start my own blog soon but I’m a little lost on everything.
    Would you recommend starting with a free platform like WordPress or go for a
    paid option? There are so many options out there that I’m completely
    confused .. Any suggestions? Kudos!

    View Comment

Leave a Reply

Your email address will not be published.

2 × 1 =