summaryrefslogtreecommitdiffstats
path: root/src/01.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/01.lisp')
-rw-r--r--src/01.lisp25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/01.lisp b/src/01.lisp
index 9646e40..7f36bf1 100644
--- a/src/01.lisp
+++ b/src/01.lisp
@@ -1,24 +1,21 @@
-(load "~/quicklisp/setup.lisp")
-(ql:quickload "uiop")
+(load "../src/common.lisp")
-(defun get-file-lines (name)
- (uiop:read-file-lines name))
+(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 parse-input (input-file)
- (mapcar 'parse-integer (get-file-lines input-file)))
+(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 part-a (parsed-input)
- (let ((sum 0) (prev 0))
- (dolist (i parsed-input)
- (if (> i prev) (progn (incf sum 1) (setf prev i))))
+(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 part-b (parsed-input)
+(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))
-
-(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"))))