""" 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)
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...')
import satx satx.engine(bits=80, cnf_path='h31.cnf', simplify=True, signed=True) x = satx.integer() y = satx.integer() z = satx.integer() assert y * (x ** 3 - y) == z ** 3 + 3 if satx.satisfy(solver='./slime', log=True): print(x, y, z) else: print('Infeasible...')
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...')
equal to the perfect cube of another natural number such that the digit sum of the first natural number is equal to the second. The name derives from Henry Dudeney, who noted the existence of these numbers in one of his puzzles. 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
""" 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...')
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...')
""" All squares of a board of a specified size (specified numbers of rows and columns) must be colored with the minimum number of colors. The four corners of any rectangle inside the board must not be assigned the same color. """ import itertools import satx n, m = 5, 8 opt = 1 while True: print('OPTIMAL? : {}'.format(opt)) satx.engine(opt.bit_length(), cnf_path='aux.cnf') # x[i][j] is the color at row i and column j x = satx.matrix(dimensions=(n, m)) # at least one corners of different color for any rectangle inside the board for i1, i2 in itertools.combinations(range(n), 2): for j1, j2 in itertools.combinations(range(m), 2): assert satx.one_of([x[i1][j1], x[i1][j2], x[i2][j1], x[i2][j2]]) != \ satx.one_of([x[i1][j1], x[i1][j2], x[i2][j1], x[i2][j2]]) satx.apply_single(satx.flatten(x), lambda t: t < opt) if satx.satisfy('slime'): print(x) break
import satx k = [114, 390, 579, 627, 633, 732, 921, 975] e = 80 satx.engine(bits=3 * e, cnf_path='sum_of_three_cubes_still_open.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]) == satx.one_of(k) 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...')
import satx satx.engine(bits=256, cnf_path='h31_xl.cnf', simplify=True, signed=True) x = satx.integer() y = satx.integer() z = satx.integer() assert y * (x**3 - y) == z**3 + 3 if satx.satisfy(solver='./slime', log=True): print(x, y, z) else: print('Infeasible...')
import satx satx.engine(bits=128, cnf_path='h31_large.cnf', simplify=True, signed=True) x = satx.integer() y = satx.integer() z = satx.integer() assert y * (x ** 3 - y) == z ** 3 + 3 if satx.satisfy(solver='./slime', log=True): print(x, y, z) else: print('Infeasible...')
import satx satx.engine(bits=32, cnf_path='brocard_problem_large.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...')
""" See https://en.wikipedia.org/wiki/Change-making_problem """ import satx k = 13 coins = [1, 5, 10, 20, 50, 100, 200] opt = k while True: satx.engine(sum(coins).bit_length(), cnf_path='aux.cnf') x = satx.vector(size=len(coins)) assert satx.dot(x, coins) == k assert sum(x) < opt if satx.satisfy('slime'): opt = sum(x) print(opt, x) else: break