commit
29afc863d6
@ -0,0 +1,2 @@
|
|||||||
|
*~
|
||||||
|
inputs/
|
@ -0,0 +1,31 @@
|
|||||||
|
;;; 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)))
|
Loading…
Reference in new issue