-
Notifications
You must be signed in to change notification settings - Fork 0
/
day05.lisp
25 lines (22 loc) · 885 Bytes
/
day05.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(defun reaction-position (string)
(loop for i from 0 to (- (length string) 2)
for x = (elt string i)
for y = (elt string (1+ i))
if (and (char-equal x y)
(or (and (lower-case-p x)
(upper-case-p y))
(and (upper-case-p x)
(lower-case-p y))))
do (return i)))
(defun remove-substring (string start &optional (end (1+ start)))
(concatenate 'string
(subseq string 0 start)
(subseq string end (length string))))
(defun react (string)
(loop for pos = (reaction-position string)
while (and pos (> (length string) 1))
do (setq string (remove-substring string pos (+ pos 2)))
finally (return string)))
(defun day05-part1 (input-file)
(with-open-file (stream input-file)
(react (read-line stream nil nil))))