From 1a046690b59d9f1dc84ee078832e5acbe3450ac9 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 13 Dec 2022 21:30:16 +0100 Subject: Documentation --- AoC2022/08/solver.lisp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'AoC2022') diff --git a/AoC2022/08/solver.lisp b/AoC2022/08/solver.lisp index 3797589..f5a273f 100644 --- a/AoC2022/08/solver.lisp +++ b/AoC2022/08/solver.lisp @@ -18,26 +18,26 @@ (defun solver-p1 (filename) "Count how many trees are visible from the outside. A tree is visible if all other trees between it and the edge of the grid are shorter." - (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename)) - (loop for base across forest-arr + (multiple-value-bind (width height forest) (forest (uiop:read-file-lines filename)) + (loop for base across forest and p from 0 count (some (lambda (direction) (loop for l in (line-of-sight direction p width height) - for tree-height = (aref forest-arr l) + for tree-height = (aref forest l) always (< tree-height base))) '(right left top bottom))))) (defun solver-p2 (filename) "A scenic score is the product of the viewing distance in each direction. The viewing distance is the lenght until a tree of equal height appears." - (multiple-value-bind (width height forest-arr) (forest (uiop:read-file-lines filename)) - (loop for base across forest-arr + (multiple-value-bind (width height forest) (forest (uiop:read-file-lines filename)) + (loop for base across forest and p from 0 maximize (apply #'* (mapcar (lambda (direction) (loop for l in (line-of-sight direction p width height) - for tree-height = (aref forest-arr l) + for tree-height = (aref forest l) count l until (>= tree-height base))) '(right left top bottom)))))) -- cgit v1.2.3