blob: 9646e40830cf64bf0257fbbd13f6474f880fb4ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
(load "~/quicklisp/setup.lisp")
(ql:quickload "uiop")
(defun get-file-lines (name)
(uiop:read-file-lines name))
;; Turn the input file into whatever form you will use for both parts
;; (get-file-lines) and (get-file-string) will be useful
(defun parse-input (input-file)
(mapcar 'parse-integer (get-file-lines input-file)))
;; Loops through two item windows on input and counts each time the first is less than the second
(defun part-a (parsed-input)
(let ((sum 0) (prev 0))
(dolist (i parsed-input)
(if (> i prev) (progn (incf sum 1) (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 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))
(time (format t "part 1: ~a~%" (part-a (parse-input "../inputs/01.txt"))))
(time (format t "part 1: ~a~%" (part-b (parse-input "../inputs/01.txt"))))
|