Compare commits

...

3 Commits

Author SHA1 Message Date
Samuel Ortion dcc3c287bb
Solve part 2 of Not Quite Lisp 2024-06-02 20:05:55 +02:00
Samuel Ortion 28948d6ed4
Not Quite Lisp... or is it ?
Solving the first question of Advent Of Code 2015 \o/
2024-06-02 19:33:40 +02:00
Samuel Ortion b2dc08f0f4
Reading a file in Common Lisp 2024-06-02 19:00:21 +02:00
3 changed files with 50 additions and 0 deletions

1
2015/days/01/data/input Normal file

File diff suppressed because one or more lines are too long

22
2015/days/01/lisp.lisp Normal file
View File

@ -0,0 +1,22 @@
;; Day 1: Not Quite Lisp
;;
;; Part 1: What is the floor Santa takes ?
(defparameter balance 0)
(defun direction (char) (cond
((char= char #\()
+1)
((char= char #\))
-1)
))
(with-open-file (in "./data/input")
(do ((char (read-char in nil)
(read-char in nil)))
((null char))
(setf balance (+ balance (direction char)))))
(print balance)

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)