We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 86de861 + dc852ec commit e040dd4Copy full SHA for e040dd4
examples/nqueens.py
@@ -13,8 +13,8 @@
13
14
x = h.addBinaries(N, N)
15
16
-h.addConstrs(x.sum(axis=0) == 1) # each row has exactly one queen
17
-h.addConstrs(x.sum(axis=1) == 1) # each col has exactly one queen
+h.addConstrs(x.sum(axis=1) == 1) # each row has exactly one queen
+h.addConstrs(x.sum(axis=0) == 1) # each col has exactly one queen
18
19
y = np.fliplr(x)
20
h.addConstrs(x.diagonal(k).sum() <= 1 for k in range(-N + 1, N)) # each diagonal has at most one queen
@@ -26,4 +26,4 @@
26
print('Queens:')
27
28
for i in range(N):
29
- print(''.join('Q' if sol[i, j] > 0.5 else '*' for j in range(N)))
+ print(''.join('Q' if sol[i, j] > 0.5 else '*' for j in range(N)))
0 commit comments