Day 8, Year 2021: Seven Segment Search
First read the problem description.
import import_ipynb
import helper
= helper.open_file('2021_8.txt')
f
= 0
c for l in f:
= l.strip()
l = l.split(' | ')
examples, output = output.split()
digits
for digit in digits:
if len(digit) in (2, 3, 4, 7):
+= 1
c
print(c)
301
from z3 import *
= Real('x')
x = Real('y')
y = Real('z')
z
= Solver()
s 3*x + 2*y - z == 1)
s.add(2*x - 2*y + 4*z == -2)
s.add(-x + 0.5*y - z == 0)
s.add(print(s.check())
print(s.model())
sat
[y = -2, x = 1, z = -2]
Source code of the solution(s):