diff options
Diffstat (limited to 'src/01.lisp')
-rw-r--r-- | src/01.lisp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/01.lisp b/src/01.lisp new file mode 100644 index 0000000..9646e40 --- /dev/null +++ b/src/01.lisp @@ -0,0 +1,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")))) |