This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by @mvolfik (helped by @chamik, gotta take some cred) for | |
# solving the 9th puzzle of Civilizace 2023 | |
n = [[15, 8, 12, 7, 10, 11, 10, 11], | |
[ 4, 2, 6, 5, 9, 8, 17, 24], | |
[ 13, 11, 11, 7, 1, 0, 8, 22], | |
[ 23, 18, 15, 14, 7, 4, 0, 9], | |
[ 19, 13, 20, 18, 7, 4, 0, 0], | |
[ 16, 19, 18, 11, 11, 6, 2, 6], | |
[ 8, 24, 17, 9, 15, 12, 8, 6], | |
[ 6, 9, 9, 4, 4, 6, 13, 7]] | |
from pulp import * | |
p = LpProblem() | |
v = [[LpVariable(name=f"{i}_{j}", cat=LpInteger, lowBound=0, upBound=9) for j in range(9)] for i in range(9)] | |
for i in range(8): | |
for j in range(8): | |
p += v[i][j] + v[i][j+1] + v[i+1][j] + v[i+1][j+1] == n[i][j] | |
# Run with -i to view the result interactively | |
p.solve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment