commit 52531e8425521cbc2d23fe5871045f138c6315d3
parent 95accd44e0c22624d279fa1ef155f93460230761
Author: Lukas Henkel <lh@entf.net>
Date: Tue, 13 Dec 2022 22:47:04 +0100
Day 13 task 2
Diffstat:
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/day13.lisp b/src/day13.lisp
@@ -41,6 +41,16 @@
when (compare-lists a b)
sum i))
+(defun task2 (inputs)
+ (let ((divider-packets (list #(#(2)) #(#(6)))))
+ (apply #'*
+ (loop for packet in (-> (remove-if #'null inputs)
+ (append (copy-seq divider-packets))
+ (sort (lambda (a b) (compare-lists a b))))
+ for i from 1
+ when (find packet divider-packets :test 'eq)
+ collect i))))
+
(define-day 13
(:translate-input (lambda (line)
(if (= (length line) 0)
@@ -51,4 +61,4 @@
(str:replace-all "," " ")
(read-from-string)))))
#'task1
- nil)
+ #'task2)
diff --git a/t/day13.lisp b/t/day13.lisp
@@ -47,3 +47,9 @@
(= 13
(run-task 13 1
(make-string-input-stream +testdata-day13+)))))
+
+(def-test day13-task2 ()
+ (is-true
+ (= 140
+ (run-task 13 2
+ (make-string-input-stream +testdata-day13+)))))