Exemplo n.º 1
0
def all_differ_from_at_most_k_pos(k, lst):
    """
    Enforce all pairs of distinct vectors of the VECTORS collection to differ from at most K positions.
    """
    nil1 = satx.integer()
    nil2 = satx.integer()
    for V in lst:
        nil1.is_not_in(V)
        nil2.is_not_in(V)
    assert nil1 == nil2
    t = satx.tensor(dimensions=(len(lst[0]),))
    assert sum(t[[i]](0, 1) for i in range(len(lst[0]))) >= len(lst[0]) - k
    for i1 in range(len(lst) - 1):
        for i2 in range(i1 + 1, len(lst)):
            for j in range(len(lst[0])):
                assert t[[j]](nil1, lst[i1][j]) == t[[j]](nil2, lst[i2][j])
Exemplo n.º 2
0
import satx

satx.engine(bits=80, cnf_path='4d_perfect_euler_bricks.cnf', simplify=True, signed=True)

a = satx.integer()
b = satx.integer()
c = satx.integer()
d = satx.integer()
p = satx.integer()
q = satx.integer()
r = satx.integer()
s = satx.integer()
t = satx.integer()
u = satx.integer()
v = satx.integer()

satx.apply_single([a, b, c, d, p, q, r, s, t, u, v], lambda x: x > 0)

assert a ** 2 + b ** 2 == p ** 2
assert a ** 2 + c ** 2 == q ** 2
assert b ** 2 + c ** 2 == r ** 2
assert a ** 2 + d ** 2 == s ** 2
assert b ** 2 + d ** 2 == t ** 2
assert c ** 2 + d ** 2 == u ** 2
assert a ** 2 + b ** 2 + c ** 2 + d ** 2 == v ** 2

if satx.satisfy(solver='./slime', log=True):
    print(a, b, c, d, p, q, r, s, t, u, v)
else:
    print('Infeasible...')
Exemplo n.º 3
0
"""
See model in OscaR

A number with an interesting property: when I divide it by v, the remainder is v-1,
and this from v ranging from 2 to 9.
It's not a small number, but it's not really big, either.
When I looked for a smaller number with this property I couldn't find one.
Can you find it?
"""

import satx

satx.engine(14, cnf_path='aux.cnf')

x = satx.integer()

for i in range(2, 10):
    assert x % i == i - 1

while satx.satisfy('kissat'):
    print(x)
Exemplo n.º 4
0
import satx

k = 33
e = 80

satx.engine(bits=3 * e, cnf_path='sum_of_three_cubes_33_unknown_representation.cnf', simplify=True, signed=True)

x = satx.integer()
y = satx.integer()
z = satx.integer()

assert satx.one_of([x ** 3 - y ** 3 - z ** 3, x ** 3 + y ** 3 - z ** 3]) == k

assert x > 8866128975287528

if satx.satisfy(solver='./slime', log=True):
    print(x, y, z, x ** 3 - y ** 3 - z ** 3, x ** 3 + y ** 3 - z ** 3)
else:
    print('Infeasible...')
Exemplo n.º 5
0
"""
See Model in OscaR

Martin Gardner Problem:
 * Call a number "prime-looking" if it is composite but not divisible by 2,3 or 5.
 * The three smallest prime-looking numbers are 49, 77 and 91.
 * There are 168 prime numbers less than 1000.
 * How many prime-looking numbers are there less than 1000?
"""

import satx

satx.engine(10, cnf_path='aux.cnf')

# the number we look for
x = satx.integer()
# a first divider
d1 = satx.integer()
# a second divider
d2 = satx.integer()

assert x < 1000
assert 2 <= d1 < 1000
assert 2 <= d2 < 1000

assert x == d1 * d2
assert x % 2 != 0
assert x % 3 != 0
assert x % 5 != 0
assert d1 <= d2
Exemplo n.º 6
0
"""
My son came to me the other day and said, "Dad, I need help with a math problem."
The problem went like this:
- We're going out to dinner taking 1-6 grandparents, 1-10 parents and/or 1-40 children
- Grandparents cost $3 for dinner, parents $2 and children $0.50
- There must be 20 total people at dinner and it must cost $20
How many grandparents, parents and children are going to dinner?
"""

import satx

satx.engine(10, cnf_path='aux.cnf')

# g is the number of grandparents
g = satx.integer()
# c is the number of children
c = satx.integer()
# p is the number of parents
p = satx.integer()

assert 1 <= g <= 7
assert 1 <= p <= 11
assert 1 <= c <= 41

assert g * 6 + p * 2 + c * 1 == 40
assert g + p + c == 20

while satx.satisfy('slime'):
    print(g, p, c)
Exemplo n.º 7
0
import satx

satx.engine(bits=80, cnf_path='3d_perfect_euler_bricks.cnf', simplify=True, signed=True)

a = satx.integer()
b = satx.integer()
c = satx.integer()

p = satx.integer()
q = satx.integer()
r = satx.integer()
s = satx.integer()

satx.apply_single([a, b, c, p, q, r, s], lambda x: x > 0)

assert a ** 2 + b ** 2 == p ** 2
assert a ** 2 + c ** 2 == q ** 2
assert b ** 2 + c ** 2 == r ** 2
assert a ** 2 + b ** 2  + c ** 2 == s ** 2

if satx.satisfy(solver='./slime', log=True):
    print(a, b, c, p, q, r, s)
else:
    print('Infeasible...')
Exemplo n.º 8
0
There are 5 non trivial numbers for base 10, and the highest such number is formed of 5 digits.
Below, the model is given for base 10.
"""

from math import ceil

import satx

# for base 10
n_digits = 5

satx.engine((10**n_digits).bit_length(), cnf_path='aux.cnf')

# n is a (non-trivial) Dudeney number
n = satx.integer()
# s is the perfect cubic root of n
s = satx.integer()
# d[i] is the ith digit of the Dudeney number
d = satx.vector(size=n_digits)

satx.apply_single(d, lambda t: t < 10)

assert 2 <= n < 10**n_digits
assert s < ceil((10**n_digits)**(1 / 3)) + 1
assert n == s * s * s
assert sum(d) == s
assert satx.dot(d, [10**(n_digits - i - 1) for i in range(n_digits)]) == n

while satx.satisfy('slime'):
    print(n, s, d)
Exemplo n.º 9
0
import satx

satx.engine(bits=16,
            cnf_path='brocard_problem.cnf',
            simplify=True,
            signed=True)

n = satx.integer()
m = satx.integer()

n.is_not_in([0, 4, 5, 7])

assert satx.factorial(n) + 1 == m**2

if satx.satisfy(solver='./slime', log=True):
    print(n, m)
else:
    print('Infeasible...')