(defun make-math-expr (operand-list)
(mapcar #'reverse
(reduce (lambda (expr-list operand)
(mapcan (lambda (expr)
(mapcar (lambda (operator)
`(,operand ,operator ,@expr))
'(+ - * /)))
expr-list))
(cdr operand-list)
:initial-value `((,(car operand-list))))))
(defun math-to-s-expr (expr)
(mapc (lambda (operator)
(loop with stack
for x = (pop expr)
while expr
do (push (if (find x operator)
(list x (pop stack) (pop expr))
x)
stack)
finally (setf expr (nreverse (cons x stack)))))
'((* /) (+ -)))
(car expr))
(defun f228 (operand-list answer)
(format t "~{~a~%~}"
(delete answer (make-math-expr operand-list)
:test-not #'=
:key (lambda (expr) (eval (math-to-s-expr expr))))))
(f228 '(1 5 3 6) 10)
(f228 '(1 5 3 6 7) 10)
KGRlZnVuIG1ha2UtbWF0aC1leHByIChvcGVyYW5kLWxpc3QpCiAgKG1hcGNhciAjJ3JldmVyc2UKCSAgKHJlZHVjZSAobGFtYmRhIChleHByLWxpc3Qgb3BlcmFuZCkKCQkgICAgKG1hcGNhbiAobGFtYmRhIChleHByKQoJCQkgICAgICAobWFwY2FyIChsYW1iZGEgKG9wZXJhdG9yKQoJCQkJCWAoLG9wZXJhbmQgLG9wZXJhdG9yICxAZXhwcikpCgkJCQkgICAgICAnKCsgLSAqIC8pKSkKCQkJICAgIGV4cHItbGlzdCkpCgkJICAoY2RyIG9wZXJhbmQtbGlzdCkKCQkgIDppbml0aWFsLXZhbHVlIGAoKCwoY2FyIG9wZXJhbmQtbGlzdCkpKSkpKQoKKGRlZnVuIG1hdGgtdG8tcy1leHByIChleHByKQogIChtYXBjIChsYW1iZGEgKG9wZXJhdG9yKQoJICAobG9vcCB3aXRoIHN0YWNrCgkJZm9yIHggPSAocG9wIGV4cHIpCgkJd2hpbGUgZXhwcgoJCWRvIChwdXNoIChpZiAoZmluZCB4IG9wZXJhdG9yKQoJCQkgICAgIChsaXN0IHggKHBvcCBzdGFjaykgKHBvcCBleHByKSkKCQkJICAgICB4KQoJCQkgc3RhY2spCgkJZmluYWxse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