#Skip to menu

Day 8, Year 2021: Seven Segment Search

First read the problem description.
import import_ipynb
import helper
f = helper.open_file('2021_8.txt')

c = 0
for l in f:
    l = l.strip()
    examples, output = l.split(' | ')
    digits = output.split()
    
    for digit in digits:
        if len(digit) in (2, 3, 4, 7):
            c += 1

print(c)
301
from z3 import *
x = Real('x')
y = Real('y')
z = Real('z')

s = Solver()
s.add(3*x + 2*y - z == 1)
s.add(2*x - 2*y + 4*z == -2)
s.add(-x + 0.5*y - z == 0)
print(s.check())
print(s.model())
sat
[y = -2, x = 1, z = -2]

Source code of the solution(s):