Solve part 2 of Not Quite Lisp

This commit is contained in:
Samuel Ortion 2024-06-02 20:05:55 +02:00
parent 28948d6ed4
commit dcc3c287bb
Signed by: sortion
GPG Key ID: 9B02406F8C4FB765
2 changed files with 30 additions and 0 deletions

View File

@ -1,4 +1,7 @@
;; Day 1: Not Quite Lisp ;; Day 1: Not Quite Lisp
;;
;; Part 1: What is the floor Santa takes ?
(defparameter balance 0) (defparameter balance 0)

27
2015/days/01/lisp2.lisp Normal file
View File

@ -0,0 +1,27 @@
;; 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)