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...')
""" 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)
""" 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)
""" See http://en.wikibooks.org/wiki/Puzzles/Arithmetical_puzzles/Digits_of_the_Square There is one four-digit whole number x, such that the last four digits of x^2 are in fact the original number x. What is it? """ import satx satx.engine(30, cnf_path='aux.cnf') # x is the number we look for x = satx.integer() # d[i] is the ith digit of x d = satx.vector(size=4) satx.apply_single(d, lambda t: t.is_in(range(10))) assert 1000 <= x < 10000 assert satx.dot(d, [1000, 100, 10, 1]) == x assert (x * x) % 10000 == x if satx.satisfy('slime'): print(x, d) else: print('Infeasible...')