summaryrefslogtreecommitdiffstats
path: root/src/01.lisp
blob: 36be5d61b1083cce48af21d5c69a24d13fdef29c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(defun 01/parse-input-direct (input)
  (mapcar 'parse-integer input))

;; Turn the input file into whatever form you will use for both parts
;; (get-file-lines) and (get-file-string) will be useful
(defun 01/parse-input (input-file)
  (01/parse-input-direct (get-file-lines input-file)))

;; Loops through two item windows on input and counts each time the first is less than the second
(defun 01/part-a (parsed-input)
  (let ((sum 0) (prev (car parsed-input)))
    (dolist (i (cons prev parsed-input))
      (when (> i prev) (incf sum))
      (setf prev i))
    sum))

;; Similar to part a, but with four item windows, comparing the sum of the first 3 with the next 3
(defun 01/part-b (parsed-input)
  (loop for (w x y z) on parsed-input until (null z) if (< (+ w x y) (+ x y z)) count w))