aboutsummaryrefslogtreecommitdiff
path: root/puzzle-1.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-06-26 07:16:31 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-06-26 10:33:39 +0100
commit6761c53d16fe52bca17b4a549f8d74c413c94992 (patch)
tree207469c4d707ba6eb1e15eb32ff19f50798de8d8 /puzzle-1.lisp
parente118b9ad2a13ae851452c34ec6c6feced0972345 (diff)
downloaddotfiles-6761c53d16fe52bca17b4a549f8d74c413c94992.tar.gz
dotfiles-6761c53d16fe52bca17b4a549f8d74c413c94992.tar.bz2
dotfiles-6761c53d16fe52bca17b4a549f8d74c413c94992.zip
(1|2)+lisp files for puzzles 1 and 2
Includes code for both rounds, separated by comments.
Diffstat (limited to 'puzzle-1.lisp')
-rw-r--r--puzzle-1.lisp26
1 files changed, 26 insertions, 0 deletions
diff --git a/puzzle-1.lisp b/puzzle-1.lisp
new file mode 100644
index 0000000..45d1921
--- /dev/null
+++ b/puzzle-1.lisp
@@ -0,0 +1,26 @@
+(defvar input (uiop:read-file-string "puzzle-1-input.txt"))
+(defvar *sep (format nil "~%~%"))
+
+(defun get-lists (input)
+ (let ((pos (search *sep input)))
+ (with-input-from-string (s (subseq input 0 pos))
+ (let ((converted
+ (loop
+ for line = (read-line s nil nil)
+ while line
+ collect (parse-integer line))))
+ (if (null pos)
+ (list converted)
+ (cons converted
+ (get-lists (subseq input (+ pos 2)))))))))
+
+(defvar sums (sort (mapcar (lambda (lst) (reduce #'+ lst)) (get-lists input)) #'>))
+
+;; First challenge
+(format t "Top snacks: ~a" (car sums))
+
+;; Second challenge
+(let ((first (car sums))
+ (second (car (cdr sums)))
+ (third (car (cdr (cdr sums)))))
+ (format t "~a,~a,~a:>~a" first second third (+ first second third)))