diff --git a/2015/days/05/nice2.lisp b/2015/days/05/nice2.lisp new file mode 100644 index 0000000..197c920 --- /dev/null +++ b/2015/days/05/nice2.lisp @@ -0,0 +1,46 @@ +(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)