adds zebrapuzzles

This commit is contained in:
Rich Jones 2025-02-03 14:34:57 +01:00
parent 5d84b6bec5
commit 0c9094e9f4
20 changed files with 2447 additions and 2 deletions

View file

@ -0,0 +1,34 @@
from z3 import *
def column(matrix, i):
return [matrix[j][i] for j in range(len(matrix))]
def instanciate_int_constrained(name, s, card):
x = Int(name)
# Each int represent an index in p[name]
s.add(x >= 0, x <= card - 1)
return x
def count_solutions(s, max=1e9):
count = 0
while s.check() == sat:
count += 1
if count >= max:
return count
m = s.model()
# Create a new constraint the blocks the current model
block = []
for d in m:
# d is a declaration
if d.arity() > 0:
raise Z3Exception("uninterpreted functions are not supported")
# create a constant from declaration
c = d()
if is_array(c) or c.sort().kind() == Z3_UNINTERPRETED_SORT:
raise Z3Exception("arrays and uninterpreted sorts are not supported")
block.append(c != m[d])
s.add(Or(block))
return count