47 lines
1.1 KiB
Common Lisp
47 lines
1.1 KiB
Common Lisp
(defun twice? (string pattern)
|
|
(numberp (search pattern string
|
|
:start2 (+
|
|
(search pattern string)
|
|
(length pattern)))))
|
|
|
|
|
|
(defvar pattern)
|
|
|
|
(defun overtwice? (string)
|
|
(loop for i from 0 to (- (length string) 2)
|
|
do
|
|
(setq pattern (subseq string i (+ i 2)))
|
|
(if (twice? string pattern)
|
|
(return-from overtwice? t))
|
|
)
|
|
nil)
|
|
|
|
(defvar c1)
|
|
(defvar c2)
|
|
(defvar c3)
|
|
(defun tandem? (string)
|
|
(loop for i from 0 to (- (length string) 3)
|
|
do
|
|
(setq c1 (char string i))
|
|
(setq c2 (char string (+ i 1)))
|
|
(setq c3 (char string (+ i 2)))
|
|
(if (and (equal c1 c3) (not (equal c1 c2)))
|
|
(return-from tandem? t)))
|
|
nil)
|
|
|
|
(defun nice? (string)
|
|
(and (overtwice? string)
|
|
(tandem? 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)
|