<jupyter_start><jupyter_text>Given a list of cities and coordinates for each city, find the shortest path as the crow flies.<jupyter_code>from random import randint
import matplotlib.pyplot as plt
import math
def generate_city_coordinates(num_cities):
    cities_coordinates = []
    for city in range(num_cities):
        x = randint(0,1000)
        y = randint(0,1000)
        cities_coordinates.append([x,y])
    return cities_coordinates
cities_coordinates = generate_city_coordinates(7)
print(cities_coordinates)
x_coords = []
y_coords = []
for coordinate in cities_coordinates:
    x_coords.append(coordinate[0])
    y_coords.append(coordinate[1])
plt.plot(x_coords, y_coords, "ro")
plt.show()
def shuffle_points(point_a, point_b, point_c):
    original_point_a = point_a[point_b]
    point_a[point_b] = point_a[point_c]
    point_a[point_c] = original_point_a
def calculate_pythagorean_distance_sum(coordinates_list):
    total_distance = 0
    for n in range(len(coordinates_list)-1):
        distance = ((coordinates_list[n][0] - coordinates_list[n+1][0]) ** 2 + (coordinates_list[n][1] - coordinates_list[n+1][1]) ** 2) ** 0.5
        total_distance += distance
    return total_distance
iteration = 0
shortest_distance = None
shortest_coordinate_path = []
x_coords = []
y_coords = []
iteration = 0
while iteration < 100000:
    iteration += 1
    point_a = randint(0, len(cities_coordinates)-1)
    point_b = randint(0, len(cities_coordinates)-1)
    shuffle_points(cities_coordinates, point_a, point_b)
    distance = calculate_pythagorean_distance_sum(cities_coordinates)
    if shortest_distance is None or distance < shortest_distance:
        shortest_distance = distance
        # shortest_coordinate_path = cities_coordinates No, references mutating value
        shortest_coordinate_path = cities_coordinates.copy()
        x_coords = []
        y_coords = []
        for coordinate in shortest_coordinate_path:
            x_coords.append(coordinate[0])
            y_coords.append(coordinate[1])
        print(f"Coordinate path: {shortest_coordinate_path} \n Shortest Distance: {shortest_distance}")
        plt.plot(x_coords, y_coords)
    plt.show()<jupyter_output>Coordinate path: [[853, 375], [815, 374], [811, 275], [718, 845], [901, 639], [61, 326], [660, 275]] 
 Shortest Distance: 2487.7631576637036
{'fraction_non_alphanumeric': 0.10438144329896908, 'fraction_numerical': 0.04209621993127148, 'mean_word_length': 4.416279069767442, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '78661', 'license': 'MIT', 'n_tokens_mistral': 858, 'n_tokens_neox': 779, 'n_words': 164, 'path': 'BruteForceTravellingSalesman.ipynb', 'repo_name': 'ElliotRedhead/TravellingSalesman', 'size': '2328'}