mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-26 17:13:17 +00:00
adds zebrapuzzles
This commit is contained in:
parent
5d84b6bec5
commit
0c9094e9f4
20 changed files with 2447 additions and 2 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue