Advent of Code Not Quite Lisp by hebiyan

(defun c (lst floor count)
  (cond
    ((= floor -1)
     (1- count))
    ((null lst)
     (1- count))
    ((char= (car lst) #\()
     (c (cdr lst) (1+ floor) (1+ count)))
    ((char= (car lst) #\))
     (c (cdr lst) (1- floor) (1+ count)))
    (t
     (1- count))))

(defun solve ()
  (labels ((inner ()
             (let ((count (c (concatenate 'list (read-line)) 0 1)))
               (format t "~a~%" count)
               (inner))))
    (handler-case
        (inner)             
      (end-of-file () nil))))
(solve)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page