(defvar *prog-input*) (let ((ui (read-line))) (if (equal ui "") (setq *prog-input* *standard-input*) (setq *prog-input* (open ui)))) (let ((cal (read-line *prog-input* NIL)) (total-score 0) (your-rps '(#\0 #\X #\Y #\Z)) (enemy-rps '(#\0 #\A #\B #\C)) (cy-rps 0) (ce-rps 0)) (loop until (or (equal cal "end") (not cal)) do (setq ce-rps (position (char cal 0) enemy-rps)) ;; We reuse numbers 1,2,3 to, for now, signify your strategy (setq cy-rps (position (char cal 2) your-rps)) ;; Similarly to part-one.cl, if we write down the table of possible combinations ;; (from left to right, columns are "Your strategy", "Enemy choice", "What your choice should be"): ;; 1 1 | 3 = 1 + 2 ;; 1 2 | 1 = 1 + 0 ;; 1 3 | 2 = 1 + 1 ;; ----+---------- ;; 2 1 | 1 = 1 + 0 ;; 2 2 | 2 = 1 + 1 ;; 2 3 | 3 = 1 + 2 ;; ----+---------- ;; 3 1 | 2 = 1 + 1 ;; 3 2 | 3 = 1 + 2 ;; 3 3 | 1 = 1 + 0 ;; Your choice is a rotation of the numbers 1, 2 and 3, where if your strategy is 1 (lose) ;; you rotate once, if your strategy is 2 (draw) you rotate zero times and if it is 3 (win) ;; you rotate two times. (setq cy-rps (+ (mod (+ cy-rps ce-rps) 3) 1)) ;; Refer to part-one.cl for explanation on math (setq total-score (+ total-score (* 3 (mod (+ (- 4 ce-rps) cy-rps) 3)) cy-rps)) (setq cal (read-line *prog-input* NIL))) (print total-score)) (if (not (eq *prog-input* *standard-input*)) (close *prog-input*))