advent-of-code-2023

My solutions to AoC 2023
git clone git://git.entf.net/advent-of-code-2023
Log | Files | Refs

commit bdfa5503a3d4ecd13dadd04919901580392ea8ab
parent 4d8a994d50d75ba86c7743d03f2975dec4a1a2f3
Author: Lukas Henkel <lh@entf.net>
Date:   Sat, 16 Dec 2023 08:32:22 +0100

Day 16 task 2

Diffstat:
Msrc/day-16.lisp | 18++++++++++++++----
Mt/day-16.lisp | 5+++--
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/day-16.lisp b/src/day-16.lisp @@ -35,10 +35,10 @@ (:up (point+ pos (cons 0 -1))) (:left (point+ pos (cons -1 0))))) -(defun shoot-beam (map) +(defun shoot-beam (map start-pos start-dir) (loop with energizing-map = (make-hash-table :test 'equal) with passing-map = (make-hash-table :test 'equal) - with todo = (list (list (cons 0 0) :right)) + with todo = (list (list start-pos start-dir)) with width = (input-map-width map) with height = (input-map-height map) for (pos direction) = (pop todo) @@ -60,5 +60,15 @@ finally (return (hash-table-count energizing-map)))) (defun day-16 (input) - (let ((map (make-map input))) - (shoot-beam map))) + (let* ((map (make-map input)) + (task-1 (shoot-beam map (cons 0 0) :right)) + (width (input-map-width map)) + (height (input-map-height map))) + (values task-1 + (max + (loop for (row dir) in `((0 :down) (,(1- height) :up)) + maximize (loop for x from 0 below width + maximize (shoot-beam map (cons x row) dir))) + (loop for (col dir) in `((0 :right) (,(1- width) :left)) + maximize (loop for y from 0 below height + maximize (shoot-beam map (cons col y) dir))))))) diff --git a/t/day-16.lisp b/t/day-16.lisp @@ -4,7 +4,7 @@ (define-test test-day-16 () - (multiple-value-bind (task-1) + (multiple-value-bind (task-1 task-2) (aoc:run-day 16 ".|...\\.... |.-.\\..... .....|-... @@ -15,4 +15,5 @@ .-.-/..|.. .|....-|.\\ ..//.|....") - (assert= 46 task-1))) + (assert= 46 task-1) + (assert= 51 task-2)))