28 lines
682 B
Common Lisp
28 lines
682 B
Common Lisp
;; Day 1: Not Quite Lisp
|
|
;;
|
|
;; Part 2: Position of the character with balance -1 (basement)
|
|
;;
|
|
;; ref.
|
|
;; - read: https://lispcookbook.github.io/cl-cookbook/files.html
|
|
|
|
(defparameter balance 0)
|
|
(defparameter position 0)
|
|
|
|
(defun direction (char) (cond
|
|
((char= char #\()
|
|
+1)
|
|
((char= char #\))
|
|
-1)
|
|
))
|
|
|
|
(with-open-file (in "./data/input")
|
|
(loop for char = (read-char in nil)
|
|
until (= balance -1)
|
|
do
|
|
(setf balance
|
|
(+ balance (direction char)))
|
|
(setf position
|
|
(+ position 1))))
|
|
|
|
(print position)
|