day5: part 1 lisp
This commit is contained in:
parent
45277d41f5
commit
c1b01e4461
|
@ -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)
|
Loading…
Reference in New Issue