(ql:quickload :fiveam) (defconstant results '((rock . scissors) (scissors . paper) (paper . rock)) "Win-lose pairs") (defun looses-to (play) (cdr (assoc play results))) (defun wins-to (play) (car (rassoc play results))) (defun translate (play) (case play ((A X) 'rock) ((B Y) 'paper) ((C Z) 'scissors))) (defun weight (play) (case play (rock 1) (paper 2) (scissors 3))) (defun match (my other) (cond ((eq my (wins-to other)) (values 6 'win)) ((eq my other) (values 3 'draw)) (t (values 0 'loose)))) (defun fixed-plays (my other) (declare (ignore other)) (translate my)) (defun reactive-plays (my other) (ecase my (X (looses-to other)) (Y other) (Z (wins-to other)))) (defun solver (strategy) (with-open-file (in "input") (loop :for op = (translate (read in nil nil)) :while op :for my = (funcall strategy (read in nil nil) op) :sum (+ (weight my) (match my op))))) (fiveam:test results (fiveam:is (= 12535 (solver #'fixed-plays))) (fiveam:is (= 15457 (solver #'reactive-plays))))