day5: part 1 lisp

This commit is contained in:
Samuel Ortion 2024-11-27 19:21:35 +01:00
parent 45277d41f5
commit c1b01e4461
Signed by: sortion
GPG Key ID: 9B02406F8C4FB765
1 changed files with 51 additions and 0 deletions

51
2015/days/05/nice.lisp Normal file
View File

@ -0,0 +1,51 @@
(defvar c)
(defvar counter)
(defun threevowels? (string)
(setq counter 0)
(loop for i from 0 to (- (length string) 1)
do (setq c (char string i))
(setq counter (+ counter (if (or
(equal c #\a)
(equal c #\e)
(equal c #\i)
(equal c #\o)
(equal c #\u))
1
0)))
(if (>= counter 3)
(return-from threevowels? t)))
nil)
(defvar c1)
(defvar c2)
(defun twice? (string)
(loop for i from 0 to (- (length string) 2)
do (setq c1 (char string i))
(setq c2 (char string (+ i 1)))
(if (equal c1 c2)
(return-from twice? t))
)
nil)
(defun redflag? (string)
(or (search "ab" string)
(search "cd" string)
(search "pq" string)
(search "xy" string)))
(defun nice? (string)
(and (threevowels? string)
(twice? string)
(not (redflag? string))))
(defvar my-count 0)
(with-open-file (in "./data/input")
(do ((line (read-line in nil)
(read-line in nil)))
((null line))
(if (nice? line)
(setq my-count (+ my-count 1)))
))
(print my-count)