Friday, February 2, 2024

I need some help with my project

I am taking a break. I have been working on a problem for the last few days and have gotten nowhere. That is not to say I have not learned. I am learning a lot. I cannot help but think about Problem-Based Learning. I have a problem, which I have not been able to conquer yet, and I am stepping away for a bit. Here is the problem. 

I am trying to do challenge. The challenge is number 9 of the 2015 Advent of Code. Full disclosure: I am using AI (ChatGPT, Copilot and Amazon Code Whisperer and Llama) to help me. These AI tools cannot do it all or really do it for you. No matter how much you use AI, you will have to make adjustments and you will face challenges and learn new things.  

Here is my code: 


#tsp = __import__('python-tsp')
#from python-tsp import tsp
#import ('python-tsp')
open = __import__('python-tsp')
#importlib.__import__('python-tsp')

import numpy as np

# Read the data from the file
data = []
with open('AOC9.txt', 'r') as file:
    for line in file:
        parts = line.strip().split()
        data.append(int(parts[-1]))

# Calculate the distance matrix
n = int(np.sqrt(2 * len(data)))
dist_matrix = np.zeros((n, n))
k = 0
for i in range(n):
    for j in range(i + 1, n):
        dist_matrix[i, j] = data[k]
        dist_matrix[j, i] = data[k]
        k += 1

# Calculate the shortest distance between all the points
path, distance = tsp(dist_matrix)

print(f"The shortest distance between all the points is {distance}.")

One of the things I learned is about naming modules. I learned that “python-tsp stands for python minus tsp. TSP stands for Traveling Salesperson. At the top of my code, one can see that I tried many different commands/lines of code to import the “python-tsp” module.  

Now I know my module is downloaded to my machine. Here is a screenshot of the file listed in my terminal.

I also know that “python-tsp” is installed in the Mu Editor 

So, what am I doing wrong?  

Here is the original challenge I am trying to solve.  


 

Any help would be appreciated. 

No comments: