Solved this mathematical problem in Python using genetic algorithms, a heuristic (shortcut) method to solve a complicated combinatorial optimization problem.
GitHub link