advent-of-code-common-lisp/2024/day-02/stage-1.lisp

25 lines
632 B
Common Lisp
Raw Normal View History

2025-01-11 23:13:49 +01:00
(asdf:load-system "cl-strings")
(require :cl-strings)
(defvar *input*
(mapcar (lambda (line)
(mapcar (lambda (column) (parse-integer column))
(cl-strings:split line " ")))
(uiop:with-safe-io-syntax ()
(uiop:read-file-lines "input.txt"))))
(defun gradual-diff-p (record)
(cond
((null (cdr record)) t)
((not (< 0 (abs (- (car record) (cadr record))) 4)) nil)
(t (gradual-diff-p (cdr record)))))
(defun safep (record)
(and (or (apply #'< record)
(apply #'> record))
(gradual-diff-p record)))
(length (delete nil (mapcar #'safep *input*)))