(defstruct entry () digs value) (defun read-input (: (name "input")) (flet ((str-to-syms (str) (flow str (spl " ") (mapcar (opip (tuples 1) (mapcar intern-fb)))))) (flow (file-get-lines name) (mapcar (do match `@a | @b` @1 (new entry digs (str-to-syms a) value (str-to-syms b))))))) (defun match-dig (syms) (match-case syms ((a b c e f g) 0) ((c f) 1) ((a c d e g) 2) ((a c d f g) 3) ((b c d f) 4) ((a b d f g) 5) ((a b d e f g) 6) ((a c f) 7) ((a b c d e f g) 8) ((a b c d f g) 9))) (defmeth entry solve (e) (each ((p (perm '(a b c d e f g)))) (let* ((map (relate '(a b c d e f g) p)) (interp (mapcar (opip (mapcar map) sort) e.digs)) (digs (remq nil [mapcar match-dig interp]))) (if (eql 10 (len digs)) (return (flow e.value (mapcar (opip (mapcar map) sort match-dig)) (poly 10))))))) (defun solve (input) (sum input .(solve)))