# Magic hexagon solver¶

Magic hexagon solver

We reduce the problem to an integer linear program.

EXAMPLES:

It allows to compare the efficiency of LP solvers:

sage: from slabbe.magic_hexagon import solve_magic_hexagon
sage: _ = solve_magic_hexagon(solver='Coin')   # not tested (>5min?)
sage: _ = solve_magic_hexagon(solver='GLPK')   # not tested (90s)
sage: _ = solve_magic_hexagon(solver='Gurobi') # not tested (<1s)

slabbe.magic_hexagon.solve_magic_hexagon(solver=None)

Solves the magic hexagon problem

We use the following convention for the positions:

    1   2  3
4  5   6   7
8   9  10  11  12
13  14  15  16
17  18  19


INPUT:

• solver – string (default:None)

EXAMPLES:

sage: from slabbe.magic_hexagon import solve_magic_hexagon
sage: a = solve_magic_hexagon()      # long time (90s if GLPK, <1s if Gurobi) # optional gurobi
sage: a                              # long time random                       # optional gurobi
[15, 14, 9, 13, 8, 6, 11, 10, 4, 5, 1, 18, 12, 2, 7, 17, 16, 19, 3]
sage: sorted(a) == list(range(1,20)) # long time                              # optional gurobi
True