Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 24, 2021 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluepichu/95993aceb9457c079f3e2882f4ce5ef7 to your computer and use it in GitHub Desktop.
Save bluepichu/95993aceb9457c079f3e2882f4ce5ef7 to your computer and use it in GitHub Desktop.
from z3 import *
with open("input.txt") as f:
lines = f.readlines()
iters = []
for i in range(14):
base = i * 18
print(lines[base + 4], lines[base + 5], lines[base + 15])
values = [
int(lines[base + 4].split(" ")[2]),
int(lines[base + 5].split(" ")[2]),
int(lines[base + 15].split(" ")[2]),
]
iters.append(values)
print(iters)
digits = [Int("d{}".format(i)) for i in range(14)]
inp_count = 0
z = 0
for a, b, c in iters:
w = digits[inp_count]
x = (z % 26) + b
z /= a
z = If(x != w, 26 * z + w + c, z)
inp_count += 1
s = Solver()
for d in digits:
s.add(d >= 1, d <= 9)
s.add(z == 0)
best = ""
while True:
if s.check() != sat:
break
out = s.model()
ans = ""
for i in range(14):
ans += str(out[digits[i]])
best = ans
print(best)
s.add(sum([digits[i] * 10 ** (13 - i) for i in range(14)]) < int(ans))
print(best)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment