Skip to content

Instantly share code, notes, and snippets.

@dmishin
dmishin / tsp_conjecture_counterexample.py
Created November 11, 2023 23:51
Use linear programming to find counterexample for a conjecture regarding the Traveling Salesman Problem
from scipy.optimize import linprog
import numpy as np
import itertools
#Searching for the counterexample for the following conjecture:
# in the shortest hamiltonian path, there is at least one
# node, connected to its 12 nearest neighbors
# https://www.reddit.com/r/math/comments/17rxc28/travelling_salesman_algorithm/
# Use linear programming to find a counterexample
@dmishin
dmishin / l1_gravity_planet.py
Created April 2, 2024 00:11
Planet shape in L1 gravity, 2D case
import numpy as np
N = 300 #size of the grid
M = 20000 #number of pixels
potential = np.zeros((N, N), dtype=np.float64)
masses = np.zeros((N, N), dtype=np.bool8)
def potential_of_mass_at(i, j):
"""Returns L1 potential of a mass at (i, j) with mass m
potential is calcualted as: