Skip to content

Instantly share code, notes, and snippets.

View gukoff's full-sized avatar

Konstantin Gukov gukoff

View GitHub Profile
@gukoff
gukoff / exchange_solver.py
Created August 2, 2026 17:24
Magic Hexagon search algorithm using simulated annealing. Optimized for performance
#!/usr/bin/env python3
"""Permutation-preserving solver for balanced abnormal magic hexagons.
This solver works in the half-turn antisymmetric branch H(-c)=-H(c), H(0)=0.
It never leaves the consecutive shell: the state is always a signed permutation
of 1..m on antipodal cell pairs. The only objective is the 3(n-1) positive-line
residual vector.
The model is equivalent to three signed triangular arrays A,B,C indexed by
0 <= a < b <= R=n-1. See the accompanying research note for the formulas.
import os
import timeit
import argparse
import statistics
def fill_env(count=1000):
for i in range(count):
os.environ[f'KEY{i}'] = f'VALUE{i}'
In case you get such an error:
dyld: Library not loaded: /usr/local/opt/x264/lib/libx264.148.dylib
Referenced from: /usr/local/Cellar/ffmpeg/3.3.2/bin/ffmpeg
Reason: image not found
Abort trap: 6
1. Run `brew reinstall x264`
2. Locate the missing library in a new place. For example, mine was at /usr/local/Cellar/x264/r2748/lib/libx264.148.dylib
3. Link the library to the needed place: `link -s /usr/local/Cellar/x264/r2748/lib/libx264.148.dylib /usr/local/opt/x264/lib/libx264.148.dylib`