Python SolutionsPython Solutions

☠️

X Marks the Spot

Week 2, 2026

All Solutions

Python solution for the treasure question | MushyZ | Python Solutions

import regex as re import matplotlib.pyplot as plt direction_pattern = re.compile(r'[NSEW]') magnitude_pattern = re.compile(r'\d+') with open("breakfun/data.txt", 'r') as file: data = file.read() directions = direction_pattern.findall(data) magnitudes = list(map(int, magnitude_pattern.findall(data))) def plot_backtrack(): x, y = 0, 0 xs = [x] ys = [y] # reverse order + reverse direction for d, m in reversed(list(zip(directions, magnitudes))): if d == 'N': y -= m elif d == 'S': y += m elif d == 'E': x -= m elif d == 'W': x += m xs.append(x) ys.append(y) plt.plot(xs, ys, marker='o') plt.title('Backtracked Path') plt.xlabel('X') plt.ylabel('Y') plt.grid() plt.show() plot_backtrack() # pirate coordinate logic X_coord = (894, -356) # X in the graph start_abs = (-576, 274.5) # LAST COORD ASSUMED TO BE STARTING POINT final = (start_abs[0] + X_coord[0], start_abs[1] + X_coord[1]) print("Treasure (most likely):", final)