diff --git a/2015/days/05/nice.lisp b/2015/days/05/nice.lisp new file mode 100644 index 0000000..029b3c6 --- /dev/null +++ b/2015/days/05/nice.lisp @@ -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)