(defvar *prog-input*) (let ((ui (read-line))) (if (equal ui "") (setq *prog-input* *standard-input*) (setq *prog-input* (open ui)))) (defun char-to-priority (c) (if (and (char<= #\a c) (char<= c #\z)) (- (char-int c) 96) ; (+ 1 (- (char-int c) (char-int #\a)) (- (char-int c) 38))) ; (+ 27 (- (char-int c) (char-int #\A)) (defun str-to-uniq-list (str) (let ((out '())) (loop for c across str do (if (not (member c out)) (push c out))) out)) (let ((inpt (read-line *prog-input* NIL)) (line-cnt 0) (encountered '()) (badge-prior 0)) (loop until (or (string= inpt "end") (not inpt)) do (if (= line-cnt 0) (setq encountered (str-to-uniq-list inpt)) (loop for c in encountered do (if (not (find c inpt)) (setq encountered (remove c encountered))))) (if (= line-cnt 2) (setq badge-prior (+ badge-prior (char-to-priority (first encountered))))) (setq line-cnt (mod (1+ line-cnt) 3)) (setq inpt (read-line *prog-input* NIL))) (print badge-prior)) (if (not (eq *prog-input* *standard-input*)) (close *prog-input*))