You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
777 B
32 lines
777 B
;;; Day 1
|
|
|
|
(defun read-1 (file)
|
|
(with-open-file (stream file)
|
|
(loop for line = (read-line stream nil)
|
|
while line
|
|
collect (parse-integer line))))
|
|
|
|
(defun solve-1-1 (file)
|
|
(let ((readings (read-1 file))
|
|
(inc-acc 0))
|
|
(labels ((rec (list old)
|
|
(if list
|
|
(progn
|
|
(if (< old (first list))
|
|
(incf inc-acc))
|
|
(rec (cdr list) (first list))))))
|
|
(rec (cdr readings) (first readings))
|
|
inc-acc)))
|
|
|
|
(defun solve-1-2 (file)
|
|
(let ((readings (read-1 file))
|
|
(inc-acc 0))
|
|
(labels ((rec (list old-sum)
|
|
(if (cddr list)
|
|
(let ((sum (reduce #'+ (subseq list 0 3))))
|
|
(if (< old-sum sum)
|
|
(incf inc-acc))
|
|
(rec (cdr list) sum)))))
|
|
(rec (cdr readings) (reduce #'+ (subseq readings 0 3)))
|
|
inc-acc)))
|