commit bdfa5503a3d4ecd13dadd04919901580392ea8ab from: Lukas Henkel date: Sat Dec 16 07:32:22 2023 UTC Day 16 task 2 commit - 4d8a994d50d75ba86c7743d03f2975dec4a1a2f3 commit + bdfa5503a3d4ecd13dadd04919901580392ea8ab blob - 396ec8a2339c5e723e63313fa58e22d6f9be35af blob + 9e964c2daca395fff8e0d7679e07b92e9d59cf52 --- src/day-16.lisp +++ 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))))))) blob - 351995254ba27a74d3a147bf87eff2c5965295d8 blob + 18a76e3d590c2fb8698c39956830270858bca53f --- t/day-16.lisp +++ 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)))